| | |
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 alignment app array barchart bitmap box broadcast c# c#gridviewcolumn cast check checkbox client combobox communication control conversion csharp custom database datagrid datagridview dataset datatable datetime degrees development draganddrop drawing elevated encryption enum excel file focus form format forms function gdi+ hospitalmanagementsystem httpwebrequest image index input install java label list listbox localization login mandelbrot math messagebox mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser whileloop windows winforms wpf xml






