public static void Main(string[] args) { int[] intArray = { 1, 2, 3, 4 }; double[] doubleArray = { 1.1, 2.1, 3.1, 4.1 }; char[] charArray = { 'a', 'b', 'c', 'd' }; //Program.toPrint(doubleArray); //Program.toPrint(charArray); //GENERIC METHODS Program.toPrint <int>(intArray); Program.toPrint <double>(doubleArray); Program.toPrint <char>(charArray); //GENERIC CLASS PrintArray <int> printIntArray = new PrintArray <int>(intArray); printIntArray.ToPrint(); PrintArray <double> printDoubleArray = new PrintArray <double>(doubleArray); printDoubleArray.ToPrint(); PrintArray <char> printCharArray = new PrintArray <char>(charArray); printCharArray.ToPrint(); new PrintArray <int>(intArray).ToPrint(); new PrintArray <double>(doubleArray).ToPrint(); new PrintArray <char>(charArray).ToPrint(); Console.ReadKey(); }
static void Main(string[] args) { int[] intArray = { 1, 2, 3, 4, 5 }; double[] doubleArray = { 1.1, 2.2, 3.3, 4.4 }; char[] charArray = { 'H', 'E', 'L', 'L', 'O' }; //ClassBasedGenerics PrintArray <int> printArray = new PrintArray <int>(intArray); printArray.ToPrint(); Console.WriteLine("--------------------------------------"); PrintArray <double> printDouble = new PrintArray <double>(doubleArray); printDouble.ToPrint(); Console.WriteLine("--------------------------------------"); new PrintArray <int>(intArray).ToPrint(); //easyway Console.WriteLine("--------------------------------------"); new PrintArray <char>(charArray).ToPrint(); Console.ReadKey(); }