Exemplo n.º 1
0
        static void ForEach()
        {
            var list = new List <MutValueType> {
                new MutValueType {
                    val = 10
                },
                new MutValueType {
                    val = 20
                },
                new MutValueType {
                    val = 30
                },
            };

            ForEach1(list);
            var array = new MutValueType[] {
                new MutValueType {
                    val = 100
                },
                new MutValueType {
                    val = 200
                },
                new MutValueType {
                    val = 300
                },
            };

            ForEachArray1(array);
        }
Exemplo n.º 2
0
 static void Using1()
 {
     Console.WriteLine("Using:");
     using (var x = new MutValueType()) {
         x.Increment();
     }
 }
Exemplo n.º 3
0
        static void Box()
        {
            object o = new MutValueType {
                val = 300
            };

            ((MutValueType)o).Increment();
            ((MutValueType)o).Increment();
        }
Exemplo n.º 4
0
        static void Using3()
        {
            Console.WriteLine("Using with variable declared outside:");
            MutValueType z;

            using (z = new MutValueType()) {
                z.Increment();
            }
        }
Exemplo n.º 5
0
        static void BoxToStringCalls()
        {
            Console.WriteLine("BoxToStringCalls:");
            MutValueType m = new MutValueType {
                val = 400
            };

            Console.WriteLine(m.ToString());
            Console.WriteLine(((object)m).ToString());
            Console.WriteLine(m.ToString());
        }
Exemplo n.º 6
0
        static void Using2()
        {
            Console.WriteLine("Not using:");
            var y = new MutValueType();

            try {
                y.Increment();
            } finally {
                MutValueType x = y;
                x.Dispose();
            }
        }
Exemplo n.º 7
0
        static void Field()
        {
            ReadonlyField.Increment();
            ReadonlyField.Increment();
            MutableField.Increment();
            MutableField.Increment();
            // Ensure that 'v' isn't incorrectly removed
            // as a compiler-generated temporary
            MutValueType v = MutableField;

            v.Increment();
            Console.WriteLine("Final value in MutableField: " + MutableField.val);
        }
Exemplo n.º 8
0
        public static void Main()
        {
            MutValueType m = new MutValueType();

            RefParameter(ref m);
            ValueParameter(m);
            Field();
            Box();
            var gvt = new GenericValueType <string>("Test");

            gvt.Call(ref gvt);
            new ValueTypeCall().InstanceFieldTests();
        }
Exemplo n.º 9
0
        static void Field()
        {
            ReadonlyField.Increment();
            ReadonlyField.Increment();
            MutableField.Increment();
            MutableField.Increment();
            // Ensure that 'v' isn't incorrectly removed
            // as a compiler-generated temporary
            MutValueType v = MutableField;

            v.Increment();
            Console.WriteLine("Final value in MutableField: " + MutableField.val);
            // Read-only field copies cannot be inlined for static methods:
            MutValueType localCopy = ReadonlyField;

            RefParameter(ref localCopy);
        }
Exemplo n.º 10
0
        static void Box()
        {
            Console.WriteLine("Box");
            object o = new MutValueType {
                val = 300
            };

            ((MutValueType)o).Increment();
            ((MutValueType)o).Increment();
            MutValueType unboxed1 = (MutValueType)o;

            unboxed1.Increment();
            unboxed1.Increment();
            ((MutValueType)o).Increment();
            MutValueType unboxed2 = (MutValueType)o;

            unboxed2.val = 100;
            ((MutValueType)o).Dispose();
        }
Exemplo n.º 11
0
 static void ValueParameter(MutValueType m)
 {
     m.Increment();
     m.Increment();
 }
Exemplo n.º 12
0
 static void RefParameter(ref MutValueType m)
 {
     m.Increment();
     m.Increment();
 }