前言:每日记录自己学习C#的心得和体会,小弟才疏学浅,如有错误的地方,欢迎大佬们指正,感谢~
1.字典的类型
public class userscore
{
public List<string> fen; //分数
public List<string> time; //时间
}
public Dictionary<string, userscore> DicScore = new Dictionary<string, userscore>(); //账户 分数
2.根据字典的值取字典的键
/// <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;
}
3.根据字典的键取字典的值
//返回账户分数的最大值
/// <summary>
/// 根据字典的键取字典的值
/// </summary>
/// <param name="str">字典的键</param>
/// <returns>字典里最大分值</returns>
public string FanhuiZuiDaZhi(string str)
{
List<int> liststr = new List<int>();
//因为分数有很多,需要找到最大的一个
foreach (var item in BaoCunScoreTime.instance.DicScore[str].fen)
{
liststr.Add(int.Parse(item));
}
int sun=0;
foreach (var item in liststr)
{
if (item >sun)
{
sun = item;
}
}
return sun.ToString ();
}
4. 根据字典键确定 值中最高分的时间
//根据字典键确定 值中最高分的时间
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;
}
/// <summary>
/// 根据键返回字典的值
/// </summary>
/// <param name="dicdata">字典</param>
/// <param name="Key_">键</param>
/// <returns></returns>
public GameObject GetDicValue(Dictionary<Transform, GameObject> dicdata, Transform Key_)
{
GameObject trans = null;
if (dicdata.ContainsKey(Key_))
{
trans = dicdata[Key_];
}
return trans;
}
/// <summary>
/// 根据值返回字典的键
/// </summary>
/// <param name="dicdata">字典</param>
/// <param name="value_">值</param>
/// <returns></returns>
public Transform GetDicKey(Dictionary<Transform, GameObject> dicdata,GameObject value_)
{
Transform trans = null;
if (dicdata.ContainsValue(value_))
{
foreach (var item in dicdata)
{
if (item.Value.Equals(value_))
{
trans = item.Key;
}
}
}
return trans;
}