I have a simple extension method that I would like to use to add an item to an array of items.
public static T[] addElement<T>(this T[] array, T elementToAdd)
{
var list = new List<T>(array) { elementToAdd };
return list.ToArray();
}
this works ok, but when I use it, I am having to set the array equal to the return value. I see that I am returning an Array. I likely want this method to be void, but I would like the item added. Does anyone have any ideas on what I need to do , to make this work the way I am wanting?
Instead of someArray = someArray.addElement(item)
, I just want to do someArray.addElement(item)
and then someArray be ready to go. What am I missing here?