C# equivalent interface mapping

G

Gavin Sullivan

How would you (if you can?) code the following VB.Net in C#?

public interface IDummy
sub SomeMethod()
end interface

public class Dummy
implements IDummy

public sub DifferentName() implements IDummy.SomeMethod

end sub

end class

Regards
 
M

Marc Gravell

You can't get 100% the same effect, but the following is pretty close; there
are some internal differences in the IL (an extra non-public method for
instance), but the effect (to the external caller) is the same (this is an
/explicit/ interface implementation):

Marc

public interface IDummy {
void SomeMethod();
}

public class Dummy : IDummy {
public void DifferentName() {

}
void IDummy.SomeMethod() {
DifferentName();
}
}

Marc
 
B

Barry Kelly

Gavin Sullivan said:
How would you (if you can?) code the following VB.Net in C#?

public interface IDummy
sub SomeMethod()
end interface

public class Dummy
implements IDummy

public sub DifferentName() implements IDummy.SomeMethod

end sub

end class

You can implement an interface with a non-public name that doesn't
conflict with any other name, whether it is inherited or if it comes
from another interface - but you can't give it an arbitrary name. You
can, of course, simply call another method:

---8<---
public interface IDummy
{
void SomeMethod();
}

public class Dummy: IDummy
{
void IDummy.SomeMethod()
{
DifferentName();
}

public void DifferentName()
{
}
}
--->8---

-- Barry
 

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