| | |
arrays
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 55
Reputation:
Solved Threads: 0
Hi
I have a code here composed of Array. I would like to know what does this mean here: (please see the red text)
What does it mean?
Thanks & regards
ArrayList numbers = new ArrayList();
string yourValue;
Console.WriteLine("Give the value (b to end)");
Console.WriteLine();
do
{
Console.WriteLine("Give the value:");
yourValue = Console.ReadLine();
if (yourValue == "b")
break;
numbers.Add(Convert.ToInt32(yourValue));
}
while (true);
System.Collections.IEnumerator Enumerator = numbers.GetEnumerator();
while (Enumerator.MoveNext())
Console.WriteLine(" " + Enumerator.Current);
I have a code here composed of Array. I would like to know what does this mean here: (please see the red text)
What does it mean?
Thanks & regards
ArrayList numbers = new ArrayList();
string yourValue;
Console.WriteLine("Give the value (b to end)");
Console.WriteLine();
do
{
Console.WriteLine("Give the value:");
yourValue = Console.ReadLine();
if (yourValue == "b")
break;
numbers.Add(Convert.ToInt32(yourValue));
}
while (true);
System.Collections.IEnumerator Enumerator = numbers.GetEnumerator();
while (Enumerator.MoveNext())
Console.WriteLine(" " + Enumerator.Current);
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
this will loop through all the values in your array
IEnumerator basically means you can use it to iterate your data
lets say you have 1, 5, 3, 8 in your array
this will print out
1 5 3 8
IEnumerator basically means you can use it to iterate your data
lets say you have 1, 5, 3, 8 in your array
this will print out
1 5 3 8
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
you don't always have to use that way, but you can
you could also do something like this
you could also do something like this
C# Syntax (Toggle Plain Text)
foreach(int num in numbers) { Console.WriteLine(" " + num); }
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Feb 2009
Posts: 55
Reputation:
Solved Threads: 0
i tried this but when I write the "b" to end, I got an error. this is what I've done.
C# Syntax (Toggle Plain Text)
while (true); //this will loop through all the values in your array IEnumerator basically means you can use it to //iterate your data foreach (int num in numbers) { Console.WriteLine(" " + num); } //System.Collections.IEnumerator Enumerator = numbers.GetEnumerator(); //while (Enumerator.MoveNext()) // Console.WriteLine(" " + Enumerator.Current); }
Last edited by tintincute; Apr 7th, 2009 at 5:11 pm.
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
its because you are using an untyped list for one, but you didn't have an else statement
also you could use List instead of ArrayList
C# Syntax (Toggle Plain Text)
if (yourValue == "b") { break; } else { numbers.Add(Convert.ToInt32(yourValue)); }
also you could use List instead of ArrayList
C# Syntax (Toggle Plain Text)
List<int> numbers = new List<int>();
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
•
•
also you could use List instead of ArrayList
C# Syntax (Toggle Plain Text)
List<int> numbers = new List<int>();
You don't really need the typed List for what's going on, it's just a nice thing to have in terms of type safety...
Last edited by alc6379; Apr 9th, 2009 at 11:08 pm.
Alex Cavnar, aka alc6379
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C# Forum
- Previous Thread: Run DLL as a App?
- Next Thread: how to connect between 2 computers in C# ?
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset date/time datetime degrees development draganddrop drawing encryption enum event excel file filename finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile gis globalization gtk httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser windows winforms wpf xml






