字典的运用

  • Post author:
  • Post category:其他


public class userscore
{
    public List<string> grade; //成绩
    public List<string> time; //时间
}
  public Dictionary<string, userscore> DicScore = new Dictionary<string, userscore>(); //用户成绩

/// <summary>
    /// 根据字典的值取字典的键
    /// </summary>
    /// <param name="str">字典的键</param>
    /// <returns>字典键的值</returns>
    public string Dictionary_Key(string str)
    {
        string strr = "";
        //BaoCunScoreTime.instance.DicScore 是字典
        foreach (var item in BaoCunScoreTime.instance.DicScore)
        {
            foreach (var itrr in item.Value.fen)
            {
                //判断字典里有没有这个分数(字典的值),有了返回出来
                if (itrr.Equals (str))
                {
                    strr= item.Key;                   
                }
            }
        }
        return strr;
    }

//根据字典键确定 值中最高分的时间
    public string ScoreZuiDaZhiTime(string str)
    {
        List<int> liststr = new List<int>();
        List<string> liststring = new List<string>();
        foreach (var item in BaoCunScoreTime.instance.DicScore[str].fen)
        {
            liststr.Add(int.Parse(item));
        }
        foreach (var item in BaoCunScoreTime.instance.DicScore[str].time)
        {
            liststring.Add(item);
        }
        int sun = 0;
        foreach (var item in liststr)
        {
            if (item > sun)
            {
                sun = item;
            }
        }
        string suning="";
        for (int i = 0; i < liststr.Count; i++)
        {
            if (liststr [i]==sun)
            {
                suning = liststring[i];
            }
        }
        return suning;
    }



版权声明:本文为changpeg原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。