Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Клас за създаване на масив:
- public static class ArrayCreator
- {
- public static T[] Create<T>(int length)
- {
- T[] arr = new T[length];
- return arr;
- }
- }
- // Главна програма за масива и за размяната на стойности
- namespace DemoTemplateMethods
- {
- public class Program
- {
- static void Main(string[] args)
- {
- string[] arr = ArrayCreator.Create<string>(5);
- for (int i = 0; i < arr.Length; i++)
- {
- string currentStr = Console.ReadLine();
- arr[i] = currentStr;
- }
- for (int i = 0; i < arr.Length; i++)
- {
- Console.WriteLine(arr[i]);
- }
- //void Swap<K>(ref K param1, ref K param2)
- //{
- // K temp;
- // temp = param1;
- // param1 = param2;
- // param2 = temp;
- //}
- //bool b1 = true;
- //bool b2 = false;
- //Console.WriteLine("b1 before = " + b1);
- //Console.WriteLine("b2 before = " + b2);
- //Swap<bool>(ref b1, ref b2);
- //Console.WriteLine("b1 after = " + b1);
- //Console.WriteLine("b2 after = " + b2);
- //string first = "First string";
- //string second = "Second string";
- //Console.WriteLine("first before = " + first);
- //Console.WriteLine("second before = " + second);
- //Swap<string>(ref first, ref second);
- //Console.WriteLine("first after = " + first);
- //Console.WriteLine("second after = " + second);
- //int x = 22;
- //int y = 33;
- //Console.WriteLine("X before = " + x );
- //Console.WriteLine("Y before = " + y );
- //Swap<int>(ref x, ref y);
- //Console.WriteLine("X after = " + x);
- //Console.WriteLine("Y after = " + y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement