Interface Property

B

Brian Corcoran

I don't normally use interfaces that much, but I have a situation where I
think it makes sense. But it is acting strange (to me anyways)

I have an interface that requires a Get for a property. But, in a class
that implements that interface,
the class provides both a get and a set for that property.

When I use that class in my code, intead of getting "Class.Property", i get
"Class.get_Property" and "Class.set_Property"

I know that the property is eventually compiled as a seperate get and set,
but I don't understand why it is showing up here.


Here's an generic example of my code:

public interface IPhone
{

string DisplayName
{
get;
}

string Extension
{
get;
}

}

public class Person : IPhone
{

public Person()
{}

private string _name;
private string _extension;

public string DisplayName
{
get { return _name; }
}

public string Extension
{
get { return _extension; }
set { _extension = value; }
}

}



public void Example()
{

Person a = new Person();
a.set_Extension = '1234';

}
 
B

Brian Corcoran

I guess this an intellisense bug.

If I code "Class.Property = "1234;" it will compile.
But the intellisence menu lists "get_Property" and "set_Property" instead
of "Property"

If I try to code "Class.set_Property("1234");" then I get a compiler error.

Is it wrong to provide more functionality than an interfacre requests?

I thought that an interface is the "minimum" but you can provide more.

I am wrong?

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top