If i have an interface:
interface IFoo
{
int Offset {get;}
}
can i have this:
interface IBar: IFoo
{
int Offset {set;}
}
so consumers of IBar will be able to set or get?
No, you can't!
(I was about to write "Yes", but after reading Anthony's post, and trying out a few tweaks, I found the answer to be NO!)
class FooBar : IFoo, IBar
{
public int Offset{get;set;}
}
(Will generate a warning as Anthony points out, which can be fixed by adding the "new" keyword.)
When trying out the code:
IBar a = new FooBar();
a.Offset = 2;
int b = a.Offset;
The last line will generate a compile error, since you have hidden IBar's Offset setter.
EDIT: Fixed the accesibillity modifier on the property in the class. Thx Anthony!
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