Example #1
0
    static void Main()
    {
        IndexedNames names = new IndexedNames();

        names[0] = "Zara";
        names[1] = "Riz";
        names[2] = "Nuha";
        names[3] = "Asif";
        names[4] = "Davinder";
        names[5] = "Sunil";
        names[6] = "Rubic";
        for (int i = 0; i < IndexedNames.size; i++)
        {
            Console.WriteLine(names[i]);
        }
    }
Example #2
0
        //static void Main(string[] args)
        //{
        //    MethodOne();
        //    MethodTwo();

        //    Console.WriteLine("Hello World!");
        //    OldMethod();
        //}

        //static void Main(string[] args)
        //{
        //    System.Reflection.MemberInfo info = typeof(MyClass);
        //    object[] attributes = info.GetCustomAttributes(true);
        //    for (int i = 0; i < attributes.Length; i++)
        //    {
        //        System.Console.WriteLine(attributes[i]);
        //    }
        //    Console.ReadKey();

        //}

        //static void Main(string[] args)
        //{
        //    Rectangle r = new Rectangle(4.5, 7.5);
        //    r.Display();
        //    Type type = typeof(Rectangle);
        //    // 遍历 Rectangle 类的特性
        //    foreach (Object attributes in type.GetCustomAttributes(false))
        //    {
        //        DeBugInfo dbi = (DeBugInfo)attributes;
        //        if (null != dbi)
        //        {
        //            Console.WriteLine("Bug no: {0}", dbi.BugNo);
        //            Console.WriteLine("Developer: {0}", dbi.Developer);
        //            Console.WriteLine("Last Reviewed: {0}",
        //                                     dbi.LastReview);
        //            Console.WriteLine("Remarks: {0}", dbi.Message);
        //        }
        //    }

        //    // 遍历方法特性
        //    foreach (MethodInfo m in type.GetMethods())
        //    {
        //        foreach (Attribute a in m.GetCustomAttributes(true))
        //        {
        //            DeBugInfo dbi = (DeBugInfo)a;
        //            if (null != dbi)
        //            {
        //                Console.WriteLine("Bug no: {0}, for Method: {1}",
        //                                              dbi.BugNo, m.Name);
        //                Console.WriteLine("Developer: {0}", dbi.Developer);
        //                Console.WriteLine("Last Reviewed: {0}",
        //                                              dbi.LastReview);
        //                Console.WriteLine("Remarks: {0}", dbi.Message);
        //            }
        //        }
        //    }
        //    Console.ReadLine();
        //}

        static void Main(string[] args)
        {
            IndexedNames index = new IndexedNames(5);

            index[0] = "Zara";
            index[1] = "Riz";
            index[2] = "Nuha";
            index[3] = "Asif";
            index[4] = "Davinder";
            for (int i = 0; i < index.size; i++)
            {
                Console.WriteLine(index[i]);
            }
            // 使用带有 string 参数的第二个索引器
            //Console.WriteLine(names["Nuha"]);
            Console.ReadKey();
        }
Example #3
0
        private void IndexedNames_Check()
        {
            string testName = "IndexedNames_Check";

            Program.Start_Check(testName);
            IndexedNames names = new IndexedNames();

            names[0] = "Zara";
            names[1] = "Riz";
            names[2] = "Nuha";
            names[3] = "Asif";
            names[4] = "Davinder";
            names[5] = "Sunil";
            names[6] = "Rubic";
            IndexedNames_0 names_0 = new IndexedNames_0();

            names_0[0] = "Zara";
            names_0[1] = "Riz";
            names_0[2] = "Nuha";
            names_0[3] = "Asif";
            names_0[4] = "Davinder";
            names_0[5] = "Sunil";
            names_0[6] = "Rubic";
            bool condition = true;

            //using the first indexer with int parameter
            for (int i = 0; i < IndexedNames.size; i++)
            {
                if (!names[0].Equals(names_0[0]))
                {
                    condition = false;
                }
            }

            Program.End_Check(testName, condition);
        }