Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class A
- {
- public void hello()
- {
- Console.WriteLine("hello");
- }
- }
- class B : A { }
- class C { }
- class Test<T> where T : A
- {
- T obj;
- public Test(T o)
- {
- obj = o;
- }
- public void sayHellow()
- {
- obj.hello();
- }
- }
- class BaseClassConstraintDemo
- {
- public static void Main()
- {
- A a = new A();
- B b = new B();
- C c = new C();
- Test<A> t1 = new Test<A>(a);
- t1.sayHellow();
- Test<B> t2 = new Test<B>(b);
- t2.sayHellow();
- Test<C> t3 = new Test<C>(c);
- t3.sayHellow();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment