Skip to main content
edited body; edited title
Source Link
Austin Salonen
  • 50.4k
  • 16
  • 112
  • 140

Instanciate Instantiate A Property Of Type List<>

I created a property of type List in my class

public List<string> CategoryRef { get; set; } 

Now when I wanna add a string to the list I try

Product p=new Product(); p.CategoryRef.Add("Nick"); 

The compiler yells at me saying the object isnt set to an instance of an object. How to I instaticateinstantiate a property?

Instanciate A Property Of Type List<>

I created a property of type List in my class

public List<string> CategoryRef { get; set; } 

Now when I wanna add a string to the list I try

Product p=new Product(); p.CategoryRef.Add("Nick"); 

The compiler yells at me saying the object isnt set to an instance of an object. How to I instaticate a property?

Instantiate A Property Of Type List<>

I created a property of type List in my class

public List<string> CategoryRef { get; set; } 

Now when I wanna add a string to the list I try

Product p=new Product(); p.CategoryRef.Add("Nick"); 

The compiler yells at me saying the object isnt set to an instance of an object. How to I instantiate a property?

Source Link
Nick LaMarca
  • 8.2k
  • 32
  • 96
  • 156

Instanciate A Property Of Type List<>

I created a property of type List in my class

public List<string> CategoryRef { get; set; } 

Now when I wanna add a string to the list I try

Product p=new Product(); p.CategoryRef.Add("Nick"); 

The compiler yells at me saying the object isnt set to an instance of an object. How to I instaticate a property?