c# - How to get array indexes using lambda expression -
i trying create string joining elements of integer array:
string.join(", ", integerarray.select(p => p.tostring()).toarray()) this way this: 1, 2, 3, 4.
now i'd print, each element index of corresponding position in array, this: {0} 1, {1} 2, {2} 3, {3} 4.
don't care format. i'm wondering how can array index each selected element in lambda expression?
select has overload takes index input lambda:
string.join(", ", integerarray.select((p, i) => string.format("[{0}] {1}",i,p)).toarray()); note use [] instead of {} avoid ugliness of using curly brackets in string.format. if really want curly brackets do:
string.join(", ", integerarray.select((p, i) => string.format("{{{0}}} {1}",i,p)).toarray())
Comments
Post a Comment