I have a List of strings called Names in a class called data. The code for the list looks like this:
public class data {
public List<string> Names = new List<string>();
Names.Add("C1");
}
When I run the program, the code fails on the line with names.Add("C1");
[edit] The error message given is “The type or namespace Names could not be found (Are you missing a using directive or an assembly reference?)“
I am going to take a shot in the dark and guess your class looks like this:
In this case the problem is infact the add method is not a member or method declaration and cannot exist where it is. One solution would be to add that in the constructor:
Another option is to add it to the declaration: