Interface and Inheritance

  • Thread starter Thread starter perspolis
  • Start date Start date
P

perspolis

Hi all
I have a calss that derived from IList.
you know that I have to implement methods of IList and make them public.
is it possible to make them private?/
becuase I saw for example in DataTable class that has derived from
IListSource but it hasen't made them public..
I got mixed up about that..
thanks in advance
 
You can implement the interface 'explicitly'. That way, the IList properties
won't appear unless the IList prefix is entered first.
 
Hi,

If you are using VS it's very easy, all you have to do is write down the
interface and you will be presented with the option of pressing TAB to
implement the stubs methods, now they are declared implicitely (not with the
prefix IList ) before, so you will have to edit them. When you do so you
will have to remove the public as they are public already
 
perspolis said:
could u show me an example??


You have:

public class MyList: IList
{
<...>
public int Add(object o)
{ whatever }
<...>
}

---- You change it to:
public class MyList: IList
{
<...>
int IList.Add(object o)
{ whatever }
<...>
}

This will hide function Add. Just do it for the rest of IList(including
ICollection and IEnumerable) functions.

Hope it helps,
MuZZy
 
"perspolis" <[email protected]> a écrit dans le message de (e-mail address removed)...

| could u show me an example??

public interface IThing
{
void DoSomething();
}

public class Thing : IThing
{
void IThing.DoSomething()
{
...
}
}

the DoSomething method is marked as private internally and can only be
accessed through an interface reference to a Thing object through IThing :

{
Thing t = new Thing();

t.DoSomething() // this won't compile, DoSomething() is private

IThing it = (IThing) t;
it.DoSomething(); // this works through the interface only
}

Joanna
 
Back
Top