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.
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With