c# - Why does this code not compile, although interfaces are reference types? -


i confused. in why interfaces in .net reference types? said interfaces in .net reference types. first code snippet not compile. says "t must reference type..."

    public isomeinterface domagic<t>(expression<func<object>> action, tuple<string, datetime, decimal> tuple)      t : isomeinterface      {       magician m = new magician();       return m.magic<t>(()=> action, tuple.item3);     } 

the second compiles.

    public isomeinterface domagic<t>(expression<func<object>> action, tuple<string, datetime, decimal> tuple)      t : class, isomeinterface      {       magician m = new magician();       return m.magic<t>(()=> action, tuple.item3);     } 

if interfaces reference types why first code snippet not compile?

because it's real type of object encapsulated inside interface. declaring isomeinterface , not define must condition: t has reference type.

because can have:

public interface istructinterface { } public struct : istructinterface { } 

and value type.

by defining additional constrain class, declare is reference type.


Comments