I have a method that takes a Generic parameter. I've restricted the type to one of two. Within the method I want to set call one of the two constructors.
Code:
internal static void CreateAddress<T>(out T address, bool isSave, int? cID) where T: Address_Accessor, Address
{
DateTime dt= DateTime.Now;
int? eID = 1;
int? sID = 50;
if (typeof(T) == typeof(Address_Accessor))
address = new Address_Accessor(dt, eID , sID);
else
address = new Address(dt, eID, sID);
}
The compile failure says:
Cannot implicitly convert type 'Address_Accessor' to 'T'. An explicit conversion exists (are you missing a cast?)
outparameter in a method that doesn't otherwise return anything instead of just returning the address?Tcan inherit from more than a class? C# doesn't support multi-inheritance.