0

How can use Generic Classes in c# ?

27th Oct 2016, 8:52 PM
MohammadReza Dehnashi
MohammadReza Dehnashi - avatar
1 Respuesta
0
using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApplication1 { public class MyArray<T> { static int index = 0; static T[] arr = new T[10]; public static void add(ref T item) { arr[index++] = item; } public static void remove(int index) { if (arr[index] != null) Array.Clear(arr, index, 1); } public static T Get(int index) { return arr[index]; } } class Test { static void Main(string[] args) { int x = 100; int y = 200; MyArray<int>.add(ref x); MyArray<int>.add(ref y); Console.WriteLine(MyArray<int>.Get(1)); Console.ReadKey(); string s1 = "Hello"; ; string s2 = "World!"; MyArray<string>.add(ref s1); MyArray<string>.add(ref s2); Console.WriteLine(MyArray<string>.Get(1)); Console.ReadKey(); } }
27th Oct 2016, 8:55 PM
MohammadReza Dehnashi
MohammadReza Dehnashi - avatar