Esempio n. 1
0
        public void clone_a_test()
        {
            var test1 = new Test("test1", x =>
            {
                x.AddComment("text");
                x.Section("grammar1");
                x.Section("grammar2");
            });

            Test test2 = test1.Clone("test2");

            test2.ShouldNotBeNull();
            test2.Name.ShouldEqual("test2");
            test2.Parts.Count.ShouldEqual(3);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Array arr = Array.CreateInstance(typeof(int), 5);
            arr.SetValue(0, 0);
            arr.SetValue(1, 1);
            arr.SetValue(2, 2);
            arr.SetValue(3, 3);
            arr.SetValue(4, 4);
            foreach (int i in arr)
            {
                Console.Write(i + "\t");
            }
            Console.WriteLine();

            Console.WriteLine("arr的维数" + arr.Rank);
            Console.WriteLine("arr的长度" + arr.Length);
            Array arrCopy = (int[])arr.Clone();

            arr.SetValue(10, 0);
            Console.WriteLine("arr的值为:");
            foreach (int i in arr)
            {
                Console.Write(i + " ");

            }
            Console.WriteLine();
            Console.WriteLine("arrCopy的值为:");
            foreach (int i in arrCopy)
            {
                Console.Write(i + " ");
            }
            //对比一下两个数组方法使用array对象,与直接使用test[]方法
            Test t0 = new Test(0);
            Test t1 = new Test(1);
            Test t2 = new Test(2);
            Test t3 = new Test(3);
            Test t4 = new Test(4);
            Array arr2 = Array.CreateInstance(typeof(Test), 5);
            arr2.SetValue(t0, 0);
            arr2.SetValue(t1, 1);
            arr2.SetValue(t2, 2);
            arr2.SetValue(t3, 3);
            arr2.SetValue(t4, 4);
            Test[] arr2Copy = (Test[])arr2.Clone();
            arr2.SetValue(new Test(10), 0);
            Console.WriteLine("arr2的值为: ");
            foreach (Test i in arr2)
            {
                Console.Write(i + " ");

            }

            Console.WriteLine();
            Console.WriteLine("arrCopy的值为:");
            foreach (Test i in arr2Copy)
            {
                Console.Write(i + " ");
            }
            Test[] arrT1 = new Test[5] { t0, t1, t2, t3, t4 };

            Test[] arrT2 = (Test[])arrT1.Clone();
            arrT1[0].iNum = 10;
            Console.WriteLine("arrT1的值为:");
            foreach (Test i in arrT1)
            {
                Console.Write(i.iNum + " ");

            }
            Console.WriteLine();
            Console.WriteLine("arrT2的值为:");
            foreach (Test i in arrT2)
            {
                Console.Write(i.iNum + " ");

            }
            Console.WriteLine();
            Console.Read();
        }