Generic interface code in c#

Vivek.Ramapuram
Posted by Vivek.Ramapuram under C# category on | Points: 40 | Views : 1049
Here We can define interfaces for generic collection classes as well as for the generic classes which represents the collection items. This is very helpful in C# programming to use the generic interfaces such as IComparable<T> rather than IComparable to avoid boxing and unboxing operations on value types.
class Program
{

static void Main()
{
char[] vowels = new char[5];

vowels[0] = 'a';
vowels[1] = 'e';
vowels[2] = 'i';
vowels[3] = 'o';
vowels[4] = 'u';
Show(vowels);
List<char> cons = new List<char>();
cons.Add('b');
cons.Add('c');
cons.Add('d');
Show(cons);
}

static void Show(IList<char> li)
{
Console.WriteLine("Total: {0}", li.Count);
foreach (char c in li)
{
Console.WriteLine(c);
}
}
}

Comments or Responses

Login to post response