So I was wondering if there's a way to add a string to a null or empty index in array list. So the thing that I want is that if the array list index is null or empty then I want it to be replaced by another text.
string[] namelist = new string[4] { "dodo", "klee", "diluc", null };
for (int i = 0; i < namelist.Count(); i++)
{
if (namelist[i] == null)
{
*Replace Null Text*
}
else
Console.WriteLine("Taken");
}
Thanks.
namelist[i] = "Whatever text you like"namelist.Lengthrather thannamelist.Count()-- it's slightly cheaperLengthorCount(). This method is called only once and it checks if the source implementsICollection<T>which is true for arrays, so it's using the arraysCountproperty (yes, arrays have it, it's simply usingLength) instead of enumerating it.