hi,I have a classB which is in location "test\folder1\generics1" and Class2 which is generic class in another folder for eg test\folder2\ and when i create object for class2 which should be able to acces class1 method which is MethodA() please advise.Thanks in advance

namespace generics1
{
    public class B
    {
       public void methodA()
        {
        }
    }
    public class A<T>
    {
        public void methodB()
        {
            base.MemberwiseClone();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            A<B> obj = new A<B>();
        }
    }
}

Something like this?

namespace generics1
{
    public class B
    {
       public void methodA()
        {
        }
    }
    public class A<T>
    {
        // Hold reference to B
        public T myObject {get; set;}

        // Constructor to recieve B
        public A<T>(T obj)
        {
            this.myObject = obj;
        }

        // Call methodA from B
        public void callMethodA()
        {
            ((B)this.myObject).methodA();
        }

        public void methodB()
        {
            base.MemberwiseClone();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            B objB = new B();
            A<B> objA = new A<B>(objB);
        }
    }
}

Edited 2 Years Ago by AleMonteiro

This article has been dead for over six months. Start a new discussion instead.