C# equivalent interface mapping

  • Thread starter Thread starter Gavin Sullivan
  • Start date Start date
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
 
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
 
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
 
Back
Top