예제 #1
0
        public static void GenericArrayMain()
        {
            Console.WriteLine("Hello World");
            MyGenericArray <int> myarray = new MyGenericArray <int>(5);

            for (int i = 0; i < 5; i++)
            {
                myarray.Setitem(i, i + 1);
            }
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(myarray.Getitem(i));
            }
            MyGenericArray <char> strarray = new MyGenericArray <char>(5);

            for (int i = 0; i < 5; i++)
            {
                strarray.Setitem(i, (char)(i + 97));
            }
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(strarray.Getitem(i));
            }
            int    a  = 10;
            int    b  = 20;
            string s1 = "satish";
            string s2 = "nagaraju";

            Swap <int>(ref a, ref b);
            Console.WriteLine("Swapped values are {0}, {1}", a, b);
            Swap <string>(ref s1, ref s2);
            Console.WriteLine("Swapped values are {0}, {1}", s1, s2);
        }
예제 #2
0
        static void Main(string[] args)
        {
            //declaring an int array
            MyGenericArray <int> intArray = new MyGenericArray <int>(5);

            //setting values
            for (int c = 0; c < 5; c++)
            {
                intArray.setItem(c, c * 5);
            }
            //retrieving the values
            for (int c = 0; c < 5; c++)
            {
                Console.Write(intArray.getItem(c) + " ");
            }
            Console.WriteLine();
            //declaring a character array
            MyGenericArray <char> charArray = new MyGenericArray <char>(5);

            //setting values
            for (int c = 0; c < 5; c++)
            {
                charArray.setItem(c, (char)(c + 97));
            }
            //retrieving the values
            for (int c = 0; c < 5; c++)
            {
                Console.Write(charArray.getItem(c) + " ");
            }
            Console.WriteLine();
            Console.ReadKey();
        }
예제 #3
0
        static void Main(string[] args)
        {
            #region CLASSENORMAL

            MyClasses m = new MyClasses();

            m[0] = int.Parse("12");
            m[1] = int.Parse("13");

            m.Swap(0, 1);

            Console.WriteLine(m[0].ToString());
            Console.WriteLine(m[1].ToString());

            #endregion

            #region CLASSENORMAL_REFS
            //MyClasses m = new MyClasses();
            int[] valores = new int[2];

            m[0]       = int.Parse("12");
            m[1]       = int.Parse("13");
            valores[0] = m[0];
            valores[1] = m[1];

            m.Swap(ref valores[0], ref valores[1]);

            Console.WriteLine(valores[0].ToString());
            Console.WriteLine(valores[1].ToString());
            #endregion

            #region CLASSEGENERIC

            //Classe de inteiros
            MyGenericArray <int> m1 = new MyGenericArray <int>();

            //uso de Indexadores
            m1[0] = 12;
            m1[1] = 13;

            //Troca valores das posições
            m1.Swap <int>(0, 1);

            Console.WriteLine(m1[0].ToString());
            Console.WriteLine(m1[1].ToString());

            //Classe de strings
            MyGenericArray <string> m2 = new MyGenericArray <string>();

            m2[0] = "12";
            m2[1] = "13";

            m2.Swap <string>(0, 1);

            Console.WriteLine(m2[0].ToString());
            Console.WriteLine(m2[1].ToString());
            #endregion

            Console.ReadKey();
        }
예제 #4
0
        public T SwapTwoArrays(MyGenericArray <T> arrayOne, MyGenericArray <T> arrayTwo, int length)
        {
            T temp;

            for (int i = 0; i < length; i++)
            {
                temp = arrayOne.ItemInArray(i);
                arrayOne.SetItem(i, arrayTwo.ItemInArray(i));
                arrayTwo.SetItem(i, temp);
            }
            return(arrayOne);
        }
예제 #5
0
        static void Main(string[] args)
        {
            MyGenericArray <int> intArray = new MyGenericArray <int>(5);

            for (int c = 0; c < 5; c++)
            {
                intArray.SetItem(c, c * 5);
            }
            for (int c = 0; c < 5; c++)
            {
                Console.Write(intArray.GetItem(c) + " ");
            }
            Console.WriteLine();

            MyGenericArray <char> charArray = new MyGenericArray <char>(5);

            for (int c = 0; c < 5; c++)
            {
                charArray.SetItem(c, (char)(c + 97));
            }
            for (int c = 0; c < 5; c++)
            {
                Console.Write(charArray.GetItem(c) + " ");
            }
            Console.WriteLine();


            int  a, b;
            char e, d;

            a = 10;
            b = 20;
            e = 'I';
            d = 'V';
            Console.WriteLine("");
            Console.WriteLine("Int values before swap:");
            Console.WriteLine("a={0}, b={1}", a, b);
            Console.WriteLine("Char values before swap:");
            Console.WriteLine("c={0}, d={1}", e, d);
            GenericMethods.Swap <int>(ref a, ref b);
            GenericMethods.Swap <char>(ref e, ref d);

            Console.WriteLine("Int values after calling swap:");
            Console.WriteLine("a = {0}, b = {1}", a, b);
            Console.WriteLine("Char values after calling swap:");
            Console.WriteLine("c = {0}, d = {1}", e, d);
            Console.WriteLine();
            Console.ReadKey();
        }
예제 #6
0
        static void Main(string[] args)
        {
            MyGenericArray <int> arr = new MyGenericArray <int>(10);

            for (int i = 0; i < 10; i++)
            {
                arr.SetItem(i, i * 10);
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(arr.GetItem(i));
            }

            Console.ReadKey();
        }
예제 #7
0
        static void Main(string[] args)
        {
            MyGenericArray <int> intArray = new MyGenericArray <int>(6);

            for (int i = 0; i < 6; i++)
            {
                intArray.SetItem(i, i * i);
            }

            MyGenericArray <int> intArrayTwo = new MyGenericArray <int>(6);

            for (int i = 0; i < 6; i++)
            {
                intArrayTwo.SetItem(i, i * i * i);
            }
        }
예제 #8
0
        static void Main(string[] args)
        {
            // Utworzenie tablicy liczb całkowitych oraz jej wypełnienie
            MyGenericArray <int> intArray = new MyGenericArray <int>(5);

            for (int i = 0; i < 5; i++)
            {
                intArray.setGenericValue(i, i * 3);
            }
            // Wypisanie wszystkich danych
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Liczba: {0}", intArray.getGenericItem(i));
            }
            // Używając tej samej generycznej klasy jesteśmy w stanie zadeklarować innym typ danych
            MyGenericArray <char> charArray = new MyGenericArray <char>(5);

            for (int i = 0; i < 5; i++)
            {
                charArray.setGenericValue(i, (char)(i + 97));
            }
            // Wypisanie wszystkich danych
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(charArray.getGenericItem(i));
            }
            Console.ReadKey();
            // Wynik działania programu
            // Liczba: 0
            // Liczba: 3
            // Liczba: 6
            // Liczba: 9
            // Liczba: 12
            // a
            // b
            // c
            // d
            // e
        }
예제 #9
0
        static void Main(string[] args)
        {
            Console.Clear();
            //declaring an array
            MyGenericArray <int> intArray = new MyGenericArray <int>(5);

            //setting value
            for (int c = 0; c < 5; c++)
            {
                intArray.setItem(c, c * 5);
            }

            //retrieving values
            for (int c = 0; c < 5; c++)
            {
                Console.WriteLine(intArray.getItem(c) + " ");
            }
            Console.WriteLine();

            //Declaring a charecter array
            MyGenericArray <char> charArray = new MyGenericArray <char>(5);

            //setting value to char array
            for (int c = 0; c < 5; c++)
            {
                charArray.setItem(c, (char)(c + 97));
            }

            //getting values from char array
            for (int c = 0; c < 5; c++)
            {
                Console.WriteLine(charArray.getItem(c) + " ");
            }

            Console.WriteLine();
            //========================

            int  a, b;
            char x, y;

            a = 10;
            b = 20;
            x = 'I';
            y = 'V';

            //dissplay values before SWAP
            Console.WriteLine("Int values before calling SWAP:");
            Console.WriteLine("a={0},b={1}", a, b);
            Console.WriteLine("char values before clling SWAP:");
            Console.WriteLine("x={0},y={1}", x, y);

            //call SWAP
            Swap <int>(ref a, ref b);
            Swap <char>(ref x, ref y);

            //dissplay values after SWAP
            Console.WriteLine("Int values after calling SWAP:");
            Console.WriteLine("a={0},b={1}", a, b);
            Console.WriteLine("char values after clling SWAP:");
            Console.WriteLine("x={0},y={1}", x, y);

            Console.ReadKey();
        }
예제 #10
0
        static void Main(string[] args)
        {
            #region CLASSENORMAL

            MyClass m = new MyClass();

            m[0] = int.Parse("12");
            m[1] = int.Parse("13");

            m.Swap(0, 1);

            Console.WriteLine(m[0].ToString());
            Console.WriteLine(m[1].ToString());

            #endregion

            #region CLASSENORMAL_REFS

            int[] valores = new int[2];

            m[0]       = int.Parse("12");
            m[1]       = int.Parse("13");
            valores[0] = m[0];
            valores[1] = m[1];

            m.Swap(ref valores[0], ref valores[1]);

            Console.WriteLine(valores[0].ToString());
            Console.WriteLine(valores[1].ToString());
            #endregion

            #region CLASSEGENERIC

            //Classe de inteiros
            MyGenericArray <int> m1 = new MyGenericArray <int>();

            //uso de Indexadores
            m1[0] = 12;
            m1[1] = 13;

            //Troca valores das posições
            m1.Swap <int>(0, 1);

            Console.WriteLine(m1[0].ToString());
            Console.WriteLine(m1[1].ToString());

            //Classe de strings
            MyGenericArray <string> m2 = new MyGenericArray <string>();

            m2[0] = "12";
            m2[1] = "13";

            m2.Swap <string>(0, 1);

            Console.WriteLine(m2[0]);
            Console.WriteLine(m2[1]);

            //Class Generica

            ReallyGeneric <MyGenericArray <string> > rgc = new ReallyGeneric <MyGenericArray <string> >(m2);

            MyGenericArray <string> xxx = rgc.Aux;


            #endregion

            #region CLASSGENERIC-I
            // Declare a List of type int, then loop through the List
            CustomList <int> list1 = new CustomList <int>();

            for (int x = 0; x < 10; x++)
            {
                list1.Add(x);
            }

            foreach (int i in list1)
            {
                System.Console.Write(i + " ");
            }
            System.Console.WriteLine("\nDone\n");

            // Declare a List of type string, then loop through the List
            CustomList <string> list2 = new CustomList <string>();
            list2.Add("Martin");
            list2.Add("Zahn");
            list2.Add("Oberdiessbach");

            foreach (string s in list2)
            {
                System.Console.Write(s + " ");
            }
            System.Console.WriteLine("\nDone\n");

            // Use Indexer on the List
            string s1 = list2[1];

            // Declare a List of type ExampleClass, then loop through the List
            // ExampleClass holds any DataType.
            CustomList <ExampleClass> list3 = new CustomList <ExampleClass>();
            ExampleClass a = new ExampleClass(7);
            list3.Add(a);

            ExampleClass b = new ExampleClass("Hello");
            list3.Add(b);

            foreach (ExampleClass o in list3)
            {
                System.Console.Write(o.objGet.ToString() + " ");
            }
            System.Console.WriteLine("\nDone");

            // Use Indexer on the List
            ExampleClass c = list3[0];
            System.Console.Write("From Indexer: " + c.objGet.ToString() + "\n");
            #endregion


            X aux = new X();
            aux.valores[0] = 12;

            X <int> aux2 = new X <int>();
            aux2.a          = 12;
            aux2.valores[0] = aux2.a;


            X <string> aux3 = new X <string>();
            aux3.a          = "ola";
            aux3.valores[0] = aux2.a.ToString();


            X <int, string> aux4 = new X <int, string>();
            aux4.a       = aux2.a;
            aux4.Valores = aux3.a;
            aux4.Valores = 12;

            X <int, MyClass> aux5 = new X <int, MyClass>();

            X <string, Hashtable> aux6 = new X <string, Hashtable>();



            Console.ReadKey();
        }