Code:
object arrayOfObjs = new object[]{ 1, "test"};
Now I want to Add new element to this array. Is it possible like:
((IEnumerable)arrayOfObjs).Cast<object>().ToList().Add("test123");
This code doesn’t add item.
Edit:
if we will make it strongly typed:
object arrayOfObjs = new string[]{ "1", "test"};
Adding work, thx:
var tmp = ((IEnumerable)arrayOfObjs).Cast<object>().ToList();
tmp.Add("test123");
How can we cast this list back to Array of T, if type is unknown at design time?
You’d need to capture the result in a local variable: