Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有多个不同字段的排序数组-不';t按字符排序_C#_Arrays_Sorting - Fatal编程技术网

C# 具有多个不同字段的排序数组-不';t按字符排序

C# 具有多个不同字段的排序数组-不';t按字符排序,c#,arrays,sorting,C#,Arrays,Sorting,这是我的班级: public class walidacja { public char znak { get; set; } public double wyj_neuron_1 { get; set; } public double wyj_neuron_2 { get; set; } public double wyj_neuron_3 { get; set; } public double wyj_neuron_1_norm { get; set;

这是我的班级:

public class walidacja
{
    public char znak { get; set; }
    public double wyj_neuron_1 { get; set; }
    public double wyj_neuron_2 { get; set; }
    public double wyj_neuron_3 { get; set; }
    public double wyj_neuron_1_norm { get; set; }
    public double wyj_neuron_2_norm { get; set; }
    public double wyj_neuron_3_norm { get; set; }
    public bool rozpoznaj { get; set; }

    public walidacja(char lit, double a, double b, double c, bool test)
    {
        this.znak = lit;
        this.wyj_neuron_1 = a;
        this.wyj_neuron_2 = b;
        this.wyj_neuron_3 = c;
        this.wyj_neuron_1_norm = a / (a + b + c);
        this.wyj_neuron_2_norm = b / (a + b + c);
        this.wyj_neuron_3_norm = c / (a + b + c);
        this.rozpoznaj = test;
    }
}
那么我宣布

valid = new walidacja[counter];
我用数据填充数组。Znak中填充的3个字母数相等(因此,如果计数器=15,则Znak字段中将有5个a、5个b、5个c)

为什么不按char znak对数组进行排序

valid.OrderBy(a => a.znak);

OrderBy
返回一个新序列,它不会更改数组。您需要将其重新分配:

valid = valid.OrderBy(a => a.znak).ToArray();

Sort/OrderBy不作用于对象-它返回一个新的
valid
ordered