My Thoughts & Views

Interface Inheritance Naming Conflicts

Posted on: March 25, 2009

Suppose you have two interfaces, lets say Interface-IA, Interface-IB & in both you have declared Name as a property as follows.

public interface IA
{

string Name { get; set; }
String Adress { get; set; }

}

public interface IB
{

string Name { get; set; }

}

Now, you write an interface -IC which derives from above 2 Interfaces as below,

public interface IA
{

int Id { get; set; }

}

When you are try to do the following, you will get an error saying ‘Ambiguity between IA.Name and IB.Name’.

class Test
{

public void GetSomething()
{
IC objIc = new IC();
Textbox1.Text = objIc.Name();
}

}

It can be solved by upcasting as below.

class Test
{

public void GetSomething()
{
IC objIc = new IC();
Textbox1.Text = ((IA)objIc).Name();
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: