I have an int[] array. I need to take an int and append it to the end of the array without affecting the position of the other items in that array. Using C# 4 and LINQ what is the most elegant way to achieve this?
My Code:
int[] items = activeList.Split(',').Select(n => Convert.ToInt32(n)).ToArray();
int itemToAdd = ddlDisabledTypes.SelectedValue.ToInt(0);
// Need final list as a string
string finalList = X
Thanks for any help!
The easiest way is to change your expression around a bit. First convert to a
List<int>, then add the element and then convert to an array.Based on your last line though it seems like you want to get all of the information back as a
stringvalue. If so then you can do the followingIf the overall goal though is to just append one more item to the end of a string then it’s much more efficient to do that directly instead of converting to an
intcollection and then back to a string.