在c#中,我对理解Enum有点困惑。是否有可能像使用字典一样使用Enum值对
在我的特异性的情况下,我需要像>
300秒= 5分钟
在我使用这个类的那一刻起名称值格式储存恒定值。
- 将可能使用枚举,所以我的Enum类会看起来很喜欢?
- 我可以存储Enum a Pair值吗?
您能否提供一份代码示例?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MyWebSite.Models
{
public class Reminders
{
private sortedDictionary<int, string> remindersValue = new SortedDictionary<int, string>();
// We are settign the default values using the Costructor
public Reminders()
{
remindersValue.Add(0, "None");
remindersValue.Add(300, "5 minutes before");
remindersValue.Add(900, "15 minutes before");
}
public SortedDictionary<int, string> GetValues()
{
return remindersValue;
}
}
}
所有'0'键的意图是什么?你的意思是指定秒数? – atlaste
感谢Stefan指出。我已经编辑了我的问题。 – GibboK
我想你应该看看[TimeSpan](http://msdn.microsoft.com/en-us/library/system.timespan.aspx)类,而不是使用这些数字。 – Default