日期:2014-05-17 浏览次数:20928 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class EnumMap<T>
{
private Dictionary<T, object> values { get; set; }
public EnumMap()
{
values = new Dictionary<T, object>();
Enum.GetValues(typeof(T)).Cast<T>().ToList().ForEach(x => values.Add(x, new object()));
}
public object this[T index]
{
get { return values[index]; }
set { values[index] = value; }
}
}
class Program
{
enum Student
{
Name, Grade, Class
};
static void Main(string[] args)
{
var student1 = new EnumMap<Student>();
student1[Student.Name] = "王二弟";
student1[Student.Grade] = 1;
student1[Student.Class] = 7;
Console.WriteLine(student1[Student.Name]);
}
}
}