Tech Off Post

Single Post Permalink

View Thread: Generi type inheritance ????
  • User profile image
    CatalinPop

    SnapshotBase snapshotInstance = new Snapshot<SnapshotBase>();

    snapshotInstance.SomeMethod1();
    snapshotInstance.SomeMethod2();
    this shoud call the SnapshotBase's methods


    ((Snapshot<SnapshotBase>) snapshotInstance).SomeMethod1();
    ((Snapshot<SnapshotBase>) snapshotInstance).SomeMethod2();

    should call Snapshot<SnapshotBase>'s methods just like in a normal inheritance scenario
    I'm not sugesting any oop rules breaking. I've told you before this shudn't replace non virtual methods using this tecnique.

    I don't realy know why you understood it like that.


    this is Exacly how my Generic class should behave, like a normal inherited class

    using System;

    using System.Collections.Generic;

    using System.Windows.Forms;

    namespace Testing {

    static class Program {

    static void Main(string[] args)

    {

          BaseClass bc = new Class2();

          bc.Write();

         ((Class2)bc).Write();

          Console.ReadKey();
    }
    }
    public class BaseClass {
       public void Write() {
          Console.WriteLine("1");
       }
    }
    public class Class2 : BaseClass {
       public void Write() {
          Console.WriteLine("2");
       }
    }

    }

    Results :

    1
    2

    [EDITED]