根据dictionary索引获取Key和Value值
var key = dictionary.ElementAt("索引值").Key;
var value= dic.ElementAt("索引值").Value;
获取一个序列的随机开始时间,并设置对应的结束时间
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("06:00", "07:30");
dic.Add("08:00", "11:30");
dic.Add("12:00", "14:00");
dic.Add("14:30", "17:00");
dic.Add("16:00", "21:00");
dic.Add("17:00", "21:00");
dic.Add("19:00", "21:00");
/// <summary>
/// 获取开始和结束时间
/// </summary>
private void GetTime(out DateTime dtStart, out DateTime dtEnd)
{
var strKey= dic.ElementAt(ran.Next(dic.Count())).Key;
var strValue = dic[strKey];
dtStart = DateTime.Parse(strKey);
dtEnd = DateTime.Parse(strValue);
}