interface as return type

Yes, you can return an interface.

Let’s say classes A and B each implement interface 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();

}

In this example func is like factory method — it can return different objects!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)