Lets say i have an array like that (I know that is not possible on c#):
string[,] arr = new string[,]
{
{"expensive", "costly", "pricy", 0},
{"black", "dark", 0}
};
So how I can add this items on list and how I can add new item between “pricy” and 0? I couldn’t find any example on the net.
Arrays are immutable, so you can’t really add or remove items from them. The only thing you can do for example is to copy the items to another array instance, minus the ones you don’t want, or do the same but use a higher dimension and add the items you need to add.
I’d recommend using a
List<T>here, whereTcould be a simple type that mirrors the things you’re adding to the array. For example:Then you can insert items:
Not sure if this would work for you, it depends on whether your ‘jagged’ data can be made to fit into
Thing. Obviously here ‘Prop1’ and so on would be the actual property names of the data you have in your array.