判断多个值中是否有重复,并返回True或False
/// <summary>
/// 判断5个组件是否有重复
/// </summary>
/// <param name="oneKey">第一块合成组件(背包占位符KEY)</param>
/// <param name="twoKey">第二块合成组件(背包占位符KEY)</param>
/// <param name="threeKey">第三块合成组件(背包占位符KEY)</param>
/// <param name="fourKey">第四块合成组件(背包占位符KEY)</param>
/// <param name="fivekey">第五块合成组件(背包占位符KEY)</param>
/// <returns>True & False</returns>
public bool JudgeHomology(int oneKey, int twoKey, int threeKey, int fourKey, int fivekey)
{
bool flag = false;
List<int> keyList = new List<int>();
int[] result = new int[5];
result[0] = oneKey;
result[1] = twoKey;
result[2] = threeKey;
result[3] = fourKey;
result[4] = fivekey;
for (int i = 0; i < result.Length; i++)
{
//若新元素没有和老元素重复
if (!keyList.Contains(result[i]))
{
keyList.Add(result[i]);
}
//和老元素重复
else
{
flag = true; //有重复
break;
}
}
return flag;
}
/// 判断5个组件是否有重复
/// </summary>
/// <param name="oneKey">第一块合成组件(背包占位符KEY)</param>
/// <param name="twoKey">第二块合成组件(背包占位符KEY)</param>
/// <param name="threeKey">第三块合成组件(背包占位符KEY)</param>
/// <param name="fourKey">第四块合成组件(背包占位符KEY)</param>
/// <param name="fivekey">第五块合成组件(背包占位符KEY)</param>
/// <returns>True & False</returns>
public bool JudgeHomology(int oneKey, int twoKey, int threeKey, int fourKey, int fivekey)
{
bool flag = false;
List<int> keyList = new List<int>();
int[] result = new int[5];
result[0] = oneKey;
result[1] = twoKey;
result[2] = threeKey;
result[3] = fourKey;
result[4] = fivekey;
for (int i = 0; i < result.Length; i++)
{
//若新元素没有和老元素重复
if (!keyList.Contains(result[i]))
{
keyList.Add(result[i]);
}
//和老元素重复
else
{
flag = true; //有重复
break;
}
}
return flag;
}