示例#1
0
        public static void Callme()
        {
            MyClassX obj1 = new MyClassX();

            obj1.value = 3;

            MyClassX obj2 = new MyClassX();

            obj2 = obj1;

            Console.WriteLine("If you chang value of variable/property from one instance then it will automatically reflect in another instance");
            obj2.value = 4;

            Console.WriteLine(obj1.value);
            Console.WriteLine(obj2.value);

            Console.WriteLine("nullifying one object does not mean instance id GCed. You need to nullify all object, if you want to do so.");
            obj1 = null; // or
            //obj2 = null;
            Console.WriteLine(obj2.value);

            Console.WriteLine("you can not/NEVER call static method using instance so i am calling it via class name");
            MyClassX.myint = 9;
            Console.WriteLine(MyClassX.myint);
            Console.WriteLine("-----------------------------------------------------------------------------------------------\n");
        }
        static void Main(string[] args)
        {
            // Type inference works on methods not on class types.
            // like PrintItems(intItems) can be called without the type but
            //var mc = new MyClassX();//  Using the generic type 'MyClassX<T>' requires 1 type arguments  but the one below works
            var mc = new MyClassX <int>();

            //List<int> intItems = new List<int>();
            //intItems.Add(1);
            //intItems.Add(2);
            //intItems.Add(3);

            //PrintItems(intItems);

            //List<string> strItems = new List<string>();
            //strItems.Add("test1");
            //strItems.Add("test2");
            //strItems.Add("test3");

            //PrintItems(strItems);

            ProduceA <MyClass2>();
            ProduceA <MyClass1>();

            Console.ReadLine();
        }