Since you are getting a null reference exception, the solution is simply:
sup.PRODUCTLIST = new product[10];
Since you would be adding the elements at runtime, I would highly recommend using other generic types that can accommodate new elements without a need of re-allocation on your part, such as
List<T>
.
The code would become:
public List<Product> PRODUCTLIST {
get {
return this.pRODUCTLISTField;
}
set {
this.pRODUCTLISTField = value;
this.RaisePropertyChanged("PRODUCTLIST");
}
}
Then, in the code you should do this,
sup.PRODUCTLIST = new List<Product>();
This is necessary in C#, otherwise
NullReferenceException
will always be raised and your program will crash.
Check out these past posts of mine to learn more on this:
Null reference exception[
^]
Problem with 'Null Reference' Error while creating Class instances[
^]
how to handle null reference and out of bound exceptions[
^]
Object reference not set to and instance of an object[
^]
What Is A Null Error in Code Execution[
^]