I want to concatenate the index value of array with its content and then save it in a new array.For example I have the array of distances arr[]={"1.3","1.5","4.6"}
I want to concatenate these distance values with their index values and store it in new array..
I want my new Array be like: new[]= {"1.3:0","1.5:1","4.6:2"}
is it possible and if yes then please tell how.. i have searched the google and find this function
var s = String.Join("; ",data.Split(',')
.Select((d, i) => d.Trim() + "= " + i.ToString())
.ToArray());
but this function is for string and my array also don't have any comma for split function. what can be the solution for it ?
The Split is to form the string[] from a string. If you already have the string[] then all you need is:
var result = yourArray.Select((item,index) => $"{item}:{index}").ToArray();
See that the $ is C#6.0 String Interpolation. If you want instead you can just use simple string concatenations or string.Format instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With