c# - get foreach sequence number on an array -


i have array s[],i'm setting with:

    string [] s;     s = data.split(','); 

after can getting elements s foreach:

foreach (string c in s)                     {                         list.items.add(c);                       } 

but want write seqeunce of c near c value i.e it'll show in list:

0 hello 1 world 2 earth 

i'm not using counter in foreach,is there way?

you have use counter. can use 1 in foreach, or use for loop , use counter.

edit: if start empty list could use list.items.count in loop print current count of items in list although really not way that.

// ugly foreach (string c in s) {     list.items.add(list.items.count + " " + c);   } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -