Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

return an interface or a class C#

// The return of interface as an instance of that interface
// Ff the instance has a few instances then no need to worry about the type of instance
// This example returns an object that has implemented Ic
public interface Ic
{
    int Type { get; }
    string Name { get; }
}

public class A : Ic
{
}

public class B : Ic
{
}

public Ic func(bool flag)
{
     if (flag)
         return new A();
       return new B();

}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #return #interface #class
ADD COMMENT
Topic
Name
6+2 =