c# - Set property to generic parameter -
I have two classes Now, I have two modes that set the Because the method works the same way, I wanted to create a method that had an input parameter of type vehicle . The method should basically do the following: The problem is, it does not recognize the How can I solve this by using generic? Please do not suggest alternative solutions without genetic (I know that there may be a value of Your code will only work if property is an example property in In addition, in your method, you do not use normal type parameters and variables: cars and
trucks , and they both Expand my
vehicle class both
cars and
trucks are the assets that look like this:
public Int wheels {get; Set; }
wheels property in some variables. I think:
Public Zero SetCarWheels (int value) {car. Wow = value; } Public Zero SetTruckWheels (int value) {Truck.Wheels = value; }
public static zero setways & lt; T & gt; (Vehicle items, int wheels) where T: vehicle {if (item! = Null) {item.Wheels = wheels; }}
wheels property.
car and
truck wheels, but for this Problems should be left in this form)
vehicles Base class:
public class vehicles {public int wheels {receive; Set; }}
public static zero SetWheels < T & gt; (T items, int wheels) where t: vehicle {if (item! = Null) {items. Wheels = wheels; }}
Comments
Post a Comment