[Mono-list] Abstract classes...

vguzev vguzev@yandex.ru
Thu, 27 May 2004 19:39:20 +0400 (MSD)


Hello!


I've found some differences between MS .Net and Mono behaviour.

Here's a little example (from RSDN forum):
8<---------------------------------------------------------
using System;

namespace TestMethods
{
 class Class1
 {
  static void Main(string[] args)
  {
   TestClass testClass = new TestClass();
   testClass.AddItem("", new TestParam());
   testClass.AddItem("", new ParamClass());

   BaseClass baseClass = testClass as BaseClass;
   baseClass.AddItem("", new TestParam());
   baseClass.AddItem("", new ParamClass());
  }
 }

 public class ParamClass {}

 public class TestParam : ParamClass {}

 public abstract class BaseClass
 {
  public abstract void AddItem(String name, ParamClass val);
 }

 public class TestClass : BaseClass
 {
  public void AddItem(String name, Object val)
  {
   Console.WriteLine("Method with 'Object val' called");
  }

  public override void AddItem(String name, ParamClass val)
  {
   Console.WriteLine("Method with 'ParamClass val' called");
  }
 }
}
8<---------------------------------------------------------

MS.Net prints the following:
8<---------------------------------------------------------
Method with 'Object val' called
Method with 'Object val' called
Method with 'ParamClass val' called
Method with 'ParamClass val' called
8<---------------------------------------------------------

Mono prints:
8<---------------------------------------------------------
Method with 'ParamClass val' called
Method with 'ParamClass val' called
Method with 'ParamClass val' called
Method with 'ParamClass val' called
8<---------------------------------------------------------

Who is right? Mono or MS .Net?


Best regards,
Vadim B. Guzev
http://u.pereslavl.ru/~vadim/MCSharp/