I have an array statsname as
apple
X
banana
Y
Kiwi
z
I need to put apple,banana and Kiwi in an array Fruits and X,Y and Z in an array called alphabets.
Any simple C# mechanism for it please ?
I have an array statsname as
apple
X
banana
Y
Kiwi
z
I need to put apple,banana and Kiwi in an array Fruits and X,Y and Z in an array called alphabets.
Any simple C# mechanism for it please ?
Then you can just do
.ToArray
on the listsUse the
IEnumerable<T>.Where
overload which supplies the index.You could make an iterator which just skips every other element. The idea is to have a "view" of a collection, special enumerable which will return only some of the elements:
You can use System.Linq.Skip to skip the first element.
Just use them as a new collection or call
.ToArray()
or.ToList()
on them:Now you have what you need.
Iterators are methods which
yield return
, see Iterators (C# Programming Guide). This is very strong feature of the language. You can: