I am wondering if someone can advice if a class can implement the following interface at one time?
interface a1
{
int mycount;
}
interface a2
{
string mycount;
}
interface a3
{
double mycount;
}
I am wondering if someone can advice if a class can implement the following interface at one time?
interface a1
{
int mycount;
}
interface a2
{
string mycount;
}
interface a3
{
double mycount;
}
None of your interfaces will compile, I'll assume they are methods and not fields.
The only way to implement multiple interfaces with conflicting membernames is by using explicit implementation:
interface a1
{
int mycount();
}
interface a2
{
string mycount();
}
class Foo : a1, a2
{
int a1.mycount() { ... }
string a2.mycount() { ... }
// you can _only_ access them through an interface reference
// even Bar members need to typecast 'this' to call these methods
void Bar()
{
var x = mycount(); // Error, won't compile
var y = (this as a2).mycount(); // Ok, y is a string
}
}