比较元组

时间:2018-08-26 07:13:45

标签: c# list sorting tuples

所以我想在这里比较元组。本质上,我有一个按特定方式排序过的数据列表,我需要弄清楚它是如何排序的。为此,我将这些数组放入元组,并以可能的方式对其进行排序。当我比较元组时,它们显然应该是正确的。元组应按“名称年龄”排序,然后权重等于未排序的原始信息,但实际上永远不会将“值”更改为正确的值。

public string Solve(string[] name, int[] age, int[] weight)
    {
        string Value = "";


        var personDefault = new List<Tuple<string, int, int>>();

        for (int i = 0; i < name.Length-1 ; i++)
        {
            personDefault.Add(new Tuple<string, int, int>(name[i], age[i], weight[i]));
        }

        var personSorted = new List<Tuple<string, int, int>>();
        personSorted = personDefault;

        personSorted = personSorted.OrderBy(s => s.Item1).ThenBy(s => s.Item2).ThenBy(s => s.Item3).ToList();
        if (personDefault.Equals(personSorted) == true)
            Value = "NAW";//Name Age Weight

        personSorted = personSorted.OrderBy(s => s.Item1).ThenBy(s => s.Item3).ThenBy(s => s.Item2).ToList();
        if (personDefault.Equals(personSorted) == true)
            Value = "NWA";//Name Weight Age

        personSorted = personSorted.OrderBy(s => s.Item2).ThenBy(s => s.Item1).ThenBy(s => s.Item3).ToList();
        if (personDefault.Equals(personSorted) == true)
            Value = "ANW";//Age Name Weight

        personSorted = personSorted.OrderBy(s => s.Item2).ThenBy(s => s.Item3).ThenBy(s => s.Item1).ToList();
        if (personDefault.Equals(personSorted) == true)
            Value = "AWN";//Age Weight Name

        personSorted = personSorted.OrderBy(s => s.Item3).ThenBy(s => s.Item2).ThenBy(s => s.Item1).ToList();
        if (personDefault.Equals(personSorted) == true)
            Value = "WAN";//Weight Age Name

        personSorted = personSorted.OrderBy(s => s.Item3).ThenBy(s => s.Item1).ThenBy(s => s.Item2).ToList();
        if (personDefault.Equals(personSorted) == true)
            Value = "WNA";//Weight Name Age
            /* 
        if (1 == 1)
            Value = "IND";//Indeterminate
        if (1 == 1)
            Value = "NOT";//None of the above
            */


        return Value;
    }

0 个答案:

没有答案