Hello!
I tested you example and it was the Dispose of OddTextReader that was
called.
I would understand it if this Dispose had been declared as virtual in
TextReader.
Here is the same as your example. Here I get the same strange result that I
don't understand.
When test is called as an interface it's test in MyDerived that is called in
spite of
having this method Test as public void Test(...) not using virtual
If I replace ITest with MyBase then Test in the MyBase is called which is
correct and understandable.
So can you explain why Test in MyDerived class is called. It should be Test
in MyBase according to my knowledge.
ITest test = new MyDerived();
test.Test();
interface ITest
{ void Test() }
public class MyBase
{ public void Test() {} }
public class MyDerived : MyBase, ITest
{ public void Test() {} }
//Tony
"Jon Skeet [C# MVP]" <sk***@pobox.comskrev i meddelandet
news:82**********************************@2g2000hs n.googlegroups.com...
On Jun 17, 12:14 pm, "Tony" <johansson.anders...@telia.comwrote:
So which Dispose in which class is called.
I far as I understand it must be in the TextReader class.
In this particular case, yes.
However, suppose you had:
public class OddTextReader : TextReader, IDisposable
{
// Abstract methods etc filled in
void IDisposable.Dispose()
{
// Some stuff here
}
}
then:
using (TextReader reader = new OddTextReader())
{
...
}
would call the OddTextReader's explicit interface implementation of
Dispose.
Jon