c# - Objects of interface, but constraint on type implementing the interface -
i've generic method constraint below:
private string getresult<t>(t myobject) t : idosomething<t> { ...... } now, problem idosomething implemented classes , not classes interface , objects created using interface type , not class like:
iclassa myobject = new classa(); so, whenever generic method called, cast must made on myobject forward parameter.
is there way avoid cast , make code work? (except option of inheriting idosomething in iclassa)
no, there's no way avoid cast in way you're doing it.
if don't want idosomething<t> , iclassa related extension , don't want use variable typed concrete class, there isn't information compiler use infer object implements right interface method without using cast.
Comments
Post a Comment