A
amaca
This does what I expect (as it should, it's from Hoffman and Kruger's C#
Unleashed):
public interface ISpeak
{
void Speak();
}
public abstract class Animal : ISpeak
{
public abstract void Speak();
}
public class Dog : Animal
{
public override void Speak()
{
Console.WriteLine( "Woof" );
}
}
public class Cat : Animal
{
public override void Speak()
{
Console.WriteLine( "Meow" );
}
}
that is, it allows me to define an interface, implement it in a base class
as an abstract method, and then override that method in an inherited class.
But I need to implement two interfaces with the same signature, and this
doesn't compile:
public interface ISpeak
{
void Speak();
}
public abstract class Animal : ISpeak
{
abstract void ISpeak.Speak(); // abstract not allowed
}
class Dog : Animal, ISpeak
{
override void ISpeak.Speak() // override not allowed
{
Console.WriteLine( "Woof" );
}
}
public class Cat : Animal
{
public override void Speak()
{
Console.WriteLine( "Meow" );
}
}
Is this simply not allowed (in which case why not?) or is there some arcane
syntax to allow this?
TIA
Andrew
Unleashed):
public interface ISpeak
{
void Speak();
}
public abstract class Animal : ISpeak
{
public abstract void Speak();
}
public class Dog : Animal
{
public override void Speak()
{
Console.WriteLine( "Woof" );
}
}
public class Cat : Animal
{
public override void Speak()
{
Console.WriteLine( "Meow" );
}
}
that is, it allows me to define an interface, implement it in a base class
as an abstract method, and then override that method in an inherited class.
But I need to implement two interfaces with the same signature, and this
doesn't compile:
public interface ISpeak
{
void Speak();
}
public abstract class Animal : ISpeak
{
abstract void ISpeak.Speak(); // abstract not allowed
}
class Dog : Animal, ISpeak
{
override void ISpeak.Speak() // override not allowed
{
Console.WriteLine( "Woof" );
}
}
public class Cat : Animal
{
public override void Speak()
{
Console.WriteLine( "Meow" );
}
}
Is this simply not allowed (in which case why not?) or is there some arcane
syntax to allow this?
TIA
Andrew