I have created an array like this
string[] directories = new string[15];
And then I want to do something with it like so
for (int i = 0; i < directories.Length; i++) {
//code
}
The user can input as many directories in the array as they want, but if they don't put 14 elements in it, the rest of the array is obviously going to be NULL and the for loop doesn't stop untill it reaches the 14th element. How can I make the loop stop at the last directory in the array and not count the NULL?
I've tried this but it returns the following error: System.NullReferenceException: 'Object reference not set to an instance of an object.'
for (int i = 0; i < directories .Length; i++) {
//code
string directory = directories[i];
if (directory.Equals(null)){
return;
}
// more code
}
Thank you and sorry for the lack of experience and bad English.