If a method returns an interface, what does it mean?

c#, interface, methods, return-value

Solution

Yes, your method could return any type that implements that interface.

Here is an example:

using System;

class Foo
{
    public IComparable GetComparable()
    {
        // Either of these return statements
        // would be valid since both System.Int32
        return 4;
        // and System.String
        return "4";
        // implement System.IComparable
    }
}

Problem

I see many methods that specify an interface as return value. Is my thought true that it means: my method can return every class type that inherits from that interface? if not please give me a good answer.

Original source