private static void TestLayoutClass() { ExplicitClass es = new ExplicitClass(); es.f1 = 100; es.f2 = 100.0f; es.f3 = "Hello"; NestedClass ns = new NestedClass(); ns.f1 = 100; ns.f2 = es; ThrowIfNotEquals(true, StructTest_NestedClass(ns), "LayoutClass marshalling scenario1 failed."); }
public static void Main() { //* MyImplicitClass instance would work with either the class or the Interface: ImplicitClass _class = new ImplicitClass(); _class.Method(); IInterface _interface = new ImplicitClass(); _interface.Method(); //* ExplicitClass would work only with the interface: ExplicitClass obj = new ExplicitClass(); //* The following line would not work and will generate a compiler error. //obj.Method(); //* Using 'var' will declare as the class, so this also will fail //var obj = new ExplicitClass(); //obj.Method(); //* This will work IInterface _explicit = new ExplicitClass(); _explicit.Method(); }