using System; namespace Generics { public class MyGeneric<T> { //type of the class is ommited private T[] array; public MyGeneric(int size) { array = new T[size + 1]; } public T getItem(int index) { return array[index]; } public void setItem(int index, T value) { array[index] = value; } } class Program { static void Main(string[] args) { //declare double array MyGeneric<double> doubleArray = new MyGeneric<double>(5); //set values double x; for (int c = 0; c < 5; c++) { x = c * 10; doubleArray.setItem(c, Convert.ToDouble(x)); } //get values for (int a = 0; a < 5; a++) { Console.WriteLine(doubleArray.getItem(a)); } Console.ReadLine(); } } }
Lemme engineeracle your Software Warcraft! One place for tech explorations of Kushan and up to date contents on cloud-based business productivity and enterprise collaboration.