Skip to content

Instantly share code, notes, and snippets.

@tnngo2
Created April 26, 2012 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnngo2/2499823 to your computer and use it in GitHub Desktop.
Save tnngo2/2499823 to your computer and use it in GitHub Desktop.
class General<T>
{
private T[] values;
private int _counter = 0;
public General(int max)
{
values = new T[max];
}
public void Add(T val)
{
if (_counter < values.Length)
{
values[_counter] = val;
_counter++;
}
}
public void Display()
{
Console.WriteLine("Constructed Class is of type: " + typeof(T));
Console.WriteLine("Values stored in the object of constructed class are: ");
for (int i = 0; i < values.Length; i++)
{
Console.WriteLine(values[i]);
}
}
}
class Students
{
static void Main(string[] args)
{
General<string> objGeneral = new General<string>(3);
objGeneral.Add("John");
objGeneral.Add("Patrick");
objGeneral.Display();
General<int> objGeneral2 = new General<int>(2);
objGeneral2.Add(200);
objGeneral2.Add(35);
objGeneral2.Display();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment