I want to add the value to null enum array. But I facing the null exception in run time. How can I fix this?
My Enum is
public enum Name
{
Arun, Kumar, Mohan, Jerwin
}
Then I create the enum array.
private static Name[] names; //here I can`t set the size. Because user can pass the input as per their need.
Now I get the value from user and add to enum array collecction. But I facing null exception in the code.
public static string GetName(Name input)
{
names[0] = input;
//My implementation
}
I am getting the error in the line names[0] = input;
.
My exception is
An unhandled exception of type 'System.NullReferenceException' occurred in my.dll
Additional information: Object reference not set to an instance of an object.
How can I add this user input to enum array?