Demonstrate using a generic interface. - CSharp Custom Type

CSharp examples for Custom Type:Generics

Description

Demonstrate using a generic interface.

Demo Code

using System;//from   ww w . j  av a2  s. c  o  m
class Program
{
    static void Main(string[] args)
    {
        Student s = new Student();
        s.Category = GradeLevel.Freshman;
        Console.WriteLine("Sudent is a {0}", s.Category);
        Employee e = new Employee();
        e.Category = EmployeeCategory.GrandPoobah;
        Console.WriteLine("Employee is a {0}", e.Category);
    }
}
interface ICategorizable<TAnEnum> where TAnEnum : struct
{
    TAnEnum Category { get; set; }
}
enum GradeLevel
{
    Freshman, Sophomore, Junior, Senior, Graduate, Playboy
}
class Student : ICategorizable<GradeLevel>
{
    public GradeLevel Category { get; set; }
}
enum EmployeeCategory
{
    FullTime, PartTime, Intern, Manager, Executive, GrandPoobah
}
class Employee : ICategorizable<EmployeeCategory>
{
    public EmployeeCategory Category { get; set; }
}

Result


Related Tutorials