How To Return an Instance of a Non-Static Class With Static Members
-
Suppose in my project I'm referencing another project as follows:
using static ProjectA;
Prior to using the static keyword in the using statement, one of my methods was able to create an instance object of a class called Products, set the values of its members, and return the instance object as shown below:
Product prod = new Models.Product();
prod.ID = unit.ID;
prod.Dept =unit.Department;
return prod;Now I'm getting errors stating that I cannot use an instance object to access members of the Product class. I tried to resolve this issue by removing the line Product prod = new Models.Product(); and going to the Product class in ProjectA and adding the static keyword to the ID and Dept properties. I can now set values of the ID and Dept properties using the class name as shown below:
Product.ID = unit.ID;
Product.Dept =unit.Department;But the big problem now is I do not have the instance object of the Product class so I cannot return it and I get an error related to that. How do I return the Product class instance in this situation?