interface - Difference between "is" and "IsAssignableFrom" C# -
this question has answer here:
what's difference between:
typeof(iinterface).isassignablefrom(typeof(class)); and
typeof(class) iinterface ?
edit: context, function this:
public static list<t> getallinstancesoftype<t>() t:entity { list<t> l = new list<t>(); if (typeof(imyinterface).isassignablefrom(typeof(t)) //or (typeof(t) imyinterface) foreach(entity e in list1) if (e t) l.add(e t); else foreach (entity e in list2) if (e t) l.add(e t); return l; }
they similar-looking conceptually different. former answers question "if had variable of type, assign value of type?"
the latter answers question "can actual value converted type via reference or boxing conversion?"
in latter case, actual object object of type type, not object of type class. make sure understand difference between:
type t = typeof(class); class c = new class(); bool b1 = t iinterface; bool b2 = c iinterface; the first asks "can type object converted interface?" , second asks "can class object converted interface?"
Comments
Post a Comment