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
Post a Comment