Has the IList extension method been used for Foreach, and depressed IEnumerable does not have this extension? (No use?? Use it, really very convenient, can be less than a few lines!! )
Do I have to use for instead of foreach in order to have an index?
Then this extension method is for you:
Public Static void Foreachread<t> ( this ienumerable<t> dx,action<int,t> Act) { int0; foreach (var in dx) { act (i, item); I+ +; }}
Finished?? Yes, I'm done.
What's the use of such a thing??
For an operation to use an index, you can only:
list<int> arr =Newlist<int> () {1,2,3,4,5,6,7,8,9,Ten};varQuery=arr. Where (x = x >5). ToList (); for(inti =0; I < query. Count; i++) {Console.WriteLine (string. Format ("{0}:{1}", I,query[i]));} Console.readkey ();
Now you can:
list<intnew list<int1,2,3,4,5, 6,7,8,9,5). Foreachread ((i, O) + = {Console.WriteLine (string. Format ("{0}:{1}", I, O);}); Console.readkey ();
Does it look like jquery!!!?
Very simple things, see others have not sent, come to the bar.
This article comes from Bo-ke-yuan
Small extension big use, oneself expand a foreachread bar