i have 1 item in a list.
But how can i use him?
publicList<Bird> Birds =newList<Bird>();
So i know i have 1 item in my list, but how can i go treugh it.
A loop would be great!
I'm sorry i'm new to Lists and could not find very much of it online :(.
thnx.
Birds(0), or Birds.Item(0), or
For Each Bird....in Birds
Hello,
you can index directly into the collection if you know it has only one item. But you can also loop through it with foreach loop or just for loop
//Access with index Bird theBird = Birds[0];//theBird.xxx = yyy;//Looping with forfor (int i = 0; i < Birds.Count; i++){ Bird theBird = Birds[i];//theBird.xxx = yyy;}//Looping with foreachforeach (Bird bin Birds){//b.xxx = yyy;}The ansers you gave is for a array not for a list...
I like to use a list... in stead of an array.
Why don't you try what the poster suggested before dis-missing it off hand. You might be surprised to find it works.
And as for not being able to find any information online! Seriously, how hard did you look?
http://msdn2.microsoft.com/en-us/library/6sh2ey19.aspx
Thanks for the link.
with this part i could finish it!
foreach(string dinosaurin dinosaurs)
{
Console.WriteLine(dinosaur);
}
Jelmer:
The ansers you gave is for a array not for a list...
I like to use a list... in stead of an array.
I at least used same generic List<Bird> as you in your code (because I usually test my code snippets before posting ;-) ). It works just the same for generic List since it implements iList<T> interface. That is, if you meant my code samples.
What Curt posted would be for index access in VB.NET.
But it don't work like i want...
With an array you could do this:
Bird(0).....
But not with my list
publicList<Bird> Birds =newList<Bird>();
I cant use Birds(0) ...
How can i access the first.. instead of making a loop treugh all Birds...
You can use the following:
Bird b = Birds[0];
Now, b will have the first item in the list.
Jelmer:
But it don't work like i want...
With an array you could do this:Bird(0).....
But not with my list
publicList<Bird> Birds =newList<Bird>();
I cant use Birds(0) ...
How can i access the first.. instead of making a loop treugh all Birds...
Yes becauseBirds(0) would be in VB.NET it doesn't work in C#. Your code is in C# when indexing happens with obj[...], that is square brackets. Very simple, try all the three examples I posted on my previous post, did you even check them?. They all work. The first one I posted is what you ask
Bird theBird = Birds[0];
0 comments:
Post a Comment