有没有更好的方法?如何避免重复的字典逻辑,并把它放在一个通用的方法?重因子重复词典C#中的逻辑
enum department { IT, CSE, MECH, EEE, ECE }
Dictionary<department, decimal> collegeDepartmentDecimal = new Dictionary<department, decimal>
{
{department.IT, 1},
{department.CSE, 45},
{department.MECH, 66},
{department.EEE, 72},
{department.ECE, 75},
};
Dictionary<department, string> collegeDepartmentString = new Dictionary<department, string>
{
{department.IT, "YES"},
{department.CSE, "NO"},
{department.MECH, "NULL"},
{department.EEE, "N/A"},
{department.ECE, null},
};
我为此使用字典。
decimal d = ("something" == collegeDepartmentDecimal[collegeDepartmentDecimal.IT] ? collegeDepartmentString[collegeDepartmentDecimal.CSE] : "something");
请帮我解决这个问题。
你到底是什么问题解决,为什么你认为使用泛型是答案? – 2015-02-24 15:19:46
我怀疑你的问题可以通过[使用属性](https://msdn.microsoft.com/en-us/library/aa288454(v = vs.71).aspx)更加优雅地解决。 – BCdotWEB 2015-02-24 15:37:06
我应该更具体。错字错误。不是泛型,只是泛型。现在,我修改了这个问题。 – Uba 2015-02-24 15:39:34