Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace week7GenericsLab
- {
- class Program
- {
- static void Main(string[] args)
- {
- MadLabClass<int> madClass = new MadLabClass<int>(10);
- MadLabClass<int> anotherClass = new MadLabClass<int>(20);
- madClass.myType[0] = 1;
- madClass.myType[1] = 2;
- madClass.myType[2] = 3;
- madClass.myType[3] = 4;
- madClass.myType[4] = 5;
- madClass.DisplayValue();
- Console.ReadKey();
- }
- }
- class MadLabClass<TOne>
- {
- public int Index;
- public TOne[] myType;
- public MadLabClass(int arraySize)
- {
- Index = 0;
- myType = new TOne[arraySize];
- }
- public void DisplayValue()
- {
- Console.WriteLine("Question 1:");
- for (int i = 0; i <= myType.Length; i++)
- {
- if (i == myType.Length)
- {
- Console.WriteLine("Question 2\n");
- Console.ReadKey();
- break;
- }
- Console.WriteLine("Value is " + myType[i] + " at index " + i);
- }
- int numX = 1;
- int numY = 2;
- string testStringA = "Hello World";
- string testStringB = "Good afternoon world";
- talkToMe<string, int>(testStringA, numX, numY);
- numX = 2;
- testStringA = "ASDF";
- talkToMe<int, string>(numX, testStringA, testStringB);
- numX = 3;
- testStringA = "test string three";
- numY = 5;
- talkToMe<string, int>(testStringA, numX, numY);
- Console.ReadKey();
- }
- public static void talkToMe<T1, T2>(T1 A, T2 B, T2 C)
- {
- T1 objA = A;
- T2 objB = B;
- T2 objC = C;
- Console.WriteLine("ObjA holds: " + objA.ToString() + " - Data type: " + objA.GetType());
- Console.WriteLine("ObjB holds: " + objB.ToString() + " - Data type: " + objB.GetType());
- Console.WriteLine("ObjC holds: " + objC.ToString() + " - Datatype: " + objC.GetType());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement