static void Main2(string[] args) { MyGenericArray <int> intArray = new MyGenericArray <int>(5); for (int i = 0; i < 5; i++) { intArray.setItem(i, i * 5); } for (int i = 0; i < 5; i++) { Console.WriteLine(intArray.getItem(i) + ""); } Console.WriteLine("\n"); MyGenericArray <char> charArray = new MyGenericArray <char>(5); for (int i = 0; i < 5; i++) { charArray.setItem(i, (char)(i + 97)); } for (int i = 0; i < 5; i++) { Console.WriteLine(charArray.getItem(i) + ""); } Console.WriteLine("\nDone"); }
private int GenericsArray_0() { int result = 0; 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++) { result += intArray.getItem(c); } 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++) { result += charArray.getItem(c); } return(result); }
protected void Page_Load(object sender, EventArgs e) { MyGenericArray <int> intArray = new MyGenericArray <int>(5); //setting values for (int c = 0; c < intArray.ArrayLength(); c++) { intArray.setItem(c, c * intArray.ArrayLength()); } //retrieving the values for (int c = 0; c < intArray.ArrayLength(); c++) { Response.Write(intArray.getItem(c) + " "); } MyGenericArray <char> charArray = new MyGenericArray <char>(5); //setting values for (int c = 0; c < intArray.ArrayLength(); c++) { charArray.setItem(c, (char)(c + 97)); } //retrieving the values for (int c = 0; c < intArray.ArrayLength(); c++) { Response.Write(charArray.getItem(c) + " "); } }
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); // c is the index which works like 0 1 2 3 4 & c* 5 is value which is 1 x 5 = 5, 2 x 5 = 10... } //retrieving the values for (int c = 0; c < 5; c++) { Console.WriteLine(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.WriteLine(charArray.getItem(c) + " "); } Console.ReadKey(); }
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(); }
static void Main(string[] args) { MyGenericArray <int> intArray = new MyGenericArray <int>(5); for (int i = 0; i < 5; i++) { intArray.setItem(i, i * 5); } //retrieving the values for (int i = 0; i < 5; i++) { Console.Write(intArray.getItem(i) + " "); } Console.WriteLine(); //declaring a character array MyGenericArray <char> charArray = new MyGenericArray <char>(5); //setting values for (int i = 0; i < 5; i++) { charArray.setItem(i, (char)(i + 98)); } //retrieving the values for (int c = 0; c < 5; c++) { Console.Write(charArray.getItem(c) + " "); } Console.WriteLine("Następne metoda generic"); Console.ReadKey(); int a, b; char e, d; a = 10; b = 20; e = 'I'; d = 'V'; //display values before swap: Console.WriteLine("Int values before calling swap:"); Console.WriteLine("a = {0}, b = {1}", a, b); Console.WriteLine("Char values before calling swap:"); Console.WriteLine("e = {0}, d = {1}", e, d); //call swap Swap <int>(ref a, ref b); Swap <char>(ref e, ref d); //display values after swap: Console.WriteLine("Int values after calling swap:"); Console.WriteLine("a = {0}, b = {1}", a, b); Console.WriteLine("Char values after calling swap:"); Console.WriteLine("e = {0}, d = {1}", e, d); Console.WriteLine("Teraz delegat"); Console.ReadKey(); //create delegate instances NumberChanger <int> nc1 = new NumberChanger <int>(AddNum); NumberChanger <int> nc2 = new NumberChanger <int>(MultNum); //calling the methods using the delegate objects nc1(25); Console.WriteLine("Value of Num: {0}", getNum()); nc2(5); Console.WriteLine("Value of Num: {0}", getNum()); Console.ReadKey(); }