Wednesday, February 27, 2008

C# quirk for the day

Let take an interface IFoo:

interface IFoo
{
void Bar()
}

We then create an abstract version of IFoo; BaseFoo:

abstract class BaseFoo : IFoo
{

}

This would compile and work no problemo in Java.


Does it work in C#?


Nope!


C# forces you to implement methods from Interfaces in abstract classes regardless of wether or not your abstract class actually needs to implement them.


So what is the solution to this problem:

abstract class BaseFoo : IFoo
{
public abstract void Bar();
}

Pretty neat huh?



No comments: