Sort排序浅聊

时间:2023-12-11 18:17:32

集合是什么?笔者简易描述:数组是不可变的,所以我们使用集合来代替。

using.System.Collections; 非泛型集合

using.System.Collections.Gernerc;泛型集合

我们现在创建一个集合,并对其排序~

            ArrayList arr1 = new ArrayList() { , , , , ,  };
arr1.Sort();
       foreach (int i in arr1)
            {
                Console.WriteLine(i);
            }

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHsAAAB0CAIAAAAq89r9AAAFc0lEQVR4nO2dbUxbVRjH+boCDhjMDXTyus3BAOdAHQzwixrNMpnB6XyJJpI4xjtsK4yXdkNgsMl0mzPTuAWH2UJcNBoTkzbhm7wtrsk++0FjSYx0lNLeWygeP5z27q69LRfofRjw/+UfUk4vyc0vT557zrmXNuLe3WFdesUyE5lREZlxjCdq+7Go7ZVR2yujdlRGe1MVvbPqMZ6nqzdK2VUTw5NZE5NZE5tZG5tZG5tVG5tVG5dVF7e7Lm533Sae7PpN2fXx2fXxOfXxOQ3xOQ0JOQ0JuQ0JuY0JuY2bcxs3P8Nz/PE93mzZc2LLs95s3Xti696TPIl5JxPz9Il5+sR8fVK+Pim/KSm/6YnnfHm++UkpL5zaxrPv1LZ9LU/xFLQkF7QkF7QmF7QmF7amFLamFLal7G9L2d+WylPUnlrUnlbUnlbcnlZsSCs2pBcb0ksM6SXGjBJjxovGCBhfMePGjm6VebmsWZd+FMaXa/y3kTHFjIyOj47fGRm7Mzw6zkeMHd261HI1xhljjLHoHVX8RaBxxpjonuPvrjvjLvecyhg7ujf4jDPGRn7/gz3MP/9O+xmP3umTrmR8nda4x+MxmS1lbYOHT996u+vmO+cH3r/YP2G1ukVBSmHFdbcoyI1z6dwyr3H+mjH259+TcuNSV2FB4Mb9Btey8XmPx2S2VF/+ue7qTw3Xfjh+47b+1qAa41w6tyz/Gcx4iBr3qs+qjcuqW7Jx/oerwPj0jMtktrQP/Hqw+6tXez4/cKGv9IteblwUBVFwuUWh9Erv0oxLNave+JK7yqox7phxmcyWVzovvXb+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序可以Reverse()翻转下

现在我申明了一个类 Person,字段Name以及Age

           ArrayList arr2 = new ArrayList() { 

new Person(){Name="Tom",Age=},
new Person(){Name="Chris",Age=},
new Person(){Name="James",Age=},
new Person (){Name="Alice",Age=}
}; arr2.Sort();

排序的时候发现报错了,日了狗。(编译通过,但是运行出错)

打开错误详情

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsMAAAG7CAIAAACpdw8kAAAgAElEQVR4nO3dabQtV0En8PuZBhWFbsVWQAaZwyxT4KngQBgFVMIUAZUAScjAEMjwSAgQAgmEJECAJISEeQ4QVBBIABEZHJ4tDijYjqB29+oP3b38UP2hrufVqz3Urn3qzL/f+q+3zj2nzq5d595d9c+5Q/YO/eGXRURERCpy4MCBvUN/+OUGAGCkgwcPHm4SKy81IiIislnRJERERKQ+kSZxk9s/93Du8Nz/dIfn7eeOz7vpHZ930zs+/6Z3fP5Nf/L5N9vPCTe70wk3u9MJ39fmzid+351P/P42dznx++9y0g+0uetJP3DXk25+1xfc/K4vuPnd9vODdzv5B+++nx+6+8k/dI9T2tziHqfc4qhTbnHUqbc46tRbHnXqLe/Z5rRb3vO0/3yvWV74X+59OD98nxfN8iP3fdGP3PfF+7nfi291vxff6n4vudX9XnKr+7/kR/dz+o/+1On/dZYHvPTHZnngS3/sgS/78TYPetmPP+hlt37QGbd+0Bm3fvAZt37wGbd58Bm3efCZt3nImbd5yJm3fciZt33IWbc9ej8/cfRZP/HQs9vc7qFn3+5hZ9/uYQdv97CDt3/YwdsfaPPyOxx4+R1+epZz7vgzh/OTP3vuLHd6+Ll3evgr2tz5EW3Ou/Mjzrvzz513l/288i4//8q7zvILr7rbLL/4qrv/4qv388hX3/2Rr77HI8+/xyPPv8cx59/jmPOPOub8o455zVGPes1Rj3rNPds8+oJ7PvqCe7V5zAX3esxr7/WY1977Ma+992PbvO4+j33dfR63n/s+7sL7Pn4/93v8hff7pYtmuf8TLrr/E17f5qee+PqfeuIb2jzgSW0ufsCTLn7gL8/yxgf+yhsfNMuvXvLgWZ58yUOefOl+jr306GMvPfrYy44+9rKjn3LZ0U+57KFPueyhT3nTQ5/6poc+9U0Pa/O0Nz/saW8+0Obpbz7w9Lf8dJtntLn8Z55x+c8ct5+fPe6tP/tr+3n4r7314c98W5tHPPNtj3jW2x7xrLe3+blnt7ni5559xc//+ixX/sJvHM4v/uZVh/Ocqx75nHfs5/h3HHP8O445/upjjr/6mOde/aj9vPNRz3vno/dzzaOff82jn3/NY9qccO1jTrj2sW1OvPaxJ77rcW1OetfjTnrX40969+NPevfjX7CfX3rBe37p5P084eT3POGU97Z54invfeKp733iqe974qnve9Kp73vSaW3e/6TT3v/LL5zlA7/yosP51Rd/cJYnv+SDT37Jh/Zz+oeOPf1Dx57+4WNP//CxL/3wU/bzkae87CNPneWMjz5tljM/+rQzP/b0Nmd97OlnfewZZ133jLOue8bZ1z3j7OuOO/u6487++HEHP37cwY//WpuXf6LNM1/+iWee84lnnvPJZ57zyWed88lnnfvJZ517/bPOvf7Z517/7Fe0+dSvv+JTv37eLL/1G688nN981W/P8pxX//ZzXv07bY4/v82njz//08e/5tPP3c9nnnvBZ543y2t/9/mzvO53T3jdZ/dz4WdPuPCzJ174uRMv/NyJF33uxIs+d9JFnzvpos+f9PrPn/T6z7+gzRtueMEbbji5zcU3nHzxjSdffOMpF994yhvbfOHUN37h1Ev2c9olXzzt0v288NIvvvCyL83yojd96UVv+r02L35zmy+/+M1ffslbZvn90y+f5Sunv/UrL53lbX/wslne/gdnvP2r+7niq2de8dUzr/jamVd87cwrv3bmlV8768qvnXXl18+66utnXfX1s9u84xtnv+MbB9tc/Y2DV//hy9u8s80fnfPOPzrnmv2ce80fn3vtfl5x7R+/4l1/0ua8d/3Jee/+k/PefajNK9/T5k9f+Z4/fdV7Z/lvr37f4Zz//j87nA/82Ws+8M39fPCbF3zwmxd88M8v+OCfX/ChP3/tfv7itR/+i9fN8pG/fN1H/vLCNh/9yws/+lcXtfnYX130sW+9vs1133r9dd96w3V//Ybr/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ERE5JAmISIiIvNEkxAREZH6aBIiIiJSH01CRERE6qNJiIiISH00CREREamPJiEiIjI6e9uu/KXQJEREREZnb29vVX+ActEOHDigSYiIiCw2bZNY+TQmz34t0CREREQWGk2i/5RDmoSIiEhxNIn+Uw5pEiIiIsVZaJPIX8hHXebHRpMQERFZRiZsEuFvTAz+DsXiyoQmISIisoxM/p5Et0ZE75zqlzbz0SRERESWkcU1ieg9S/t+hyYhIiKyjEzbJHqlYUHvN5REkxAREVlGJm8Ss9LQ/bf7oe9uiIiIbE8mbBJhhxhsCYt7o0KTEBERWUYW8d2NzHsSvduahIiIyGZnoU0i9Z5Et0ks6AcpNAkREZFlZMk/J9G77T0JERGRzc7yv7sRfXTyaBIiIiLLyLRNojts78OwOvjdDRERkY3PgprEyqNJiIiILCOaRP8phzQJERGR4rRN4uA2KmwSs9pwUJMQEREZm729vQPba7BJNE1z3HHHtbc1CRERkdGJ/tjjNskce1sjNAkREREZnV6NOKRJiIiISGG6NcLPSYiIiMiI9GqE726IiIhIacIaoUmIiIhIUTI14pAmISIiIpmkaoSfkxAREZGBZGqE726IiIhILvkaoUmIiIhIMoU14pAmISIiIr2U14hDmoSIiIh0M6pGHNIkREREZJ5oEiIiIlIfTUJERETqc7hJHAQAGO/AgQN7BwAAav1/4H2vZtoNEv0AAAAASUVORK5CYII=" alt="" />

异常详情:{"必须至少有一个对象实现 IComparable。"}

出错原因:没有给对象指定一个标准来判定比较
就好比你告诉班长(C#)对整个班级进行大小排序,班长会无法执行,为什么呢?因为班里面的人(对象)可以比较年龄、身高、体重等等,所以班长不知道你到底需要比较什么?
所以我们需要实现 IComparable 接口来实现对一个标准进行比较
   class Person:IComparable
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
} private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
} public int CompareTo(object obj)
{
Person p = obj as Person;
if (p != null)
{
return this.Age- p.Age;//或者比较Name长度,this.Name.Length
}
else
{
throw new ArgumentException();
}
}

Get:

aaarticlea/png;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ZJjiWsbcM5Jew2X8EOAyThFcz2Uc1nqcAylkreQfKa0KmQ3SWOKCy/gRwGUci1zQZVyWFnv4Gd+4ldbPwzO4jO8HLuN0lAu6jN2ol1TDhkBJb0v3j23M1zLmhmJ+TLiMHwBcxux0l3YZs13jAsc9UR9nzItrGbO+X5i4h8v4MTQy+d4CcBnfAVzGVSAtBlzGZ4HLuA6kBYAIkBYAIkBaAIgAaQEgAqQFgAiQFgAiQFoAiABpASBCC9JqxmVc5HrW4+i20rkht7gApPcH1zI+evZKOZHfi2fr8bAKvhHrcQvS8m24jItc1npsaTCFG9sfvMxxA9bj3E7SkPUYLuNdLms9noimfHEttj1RSWXxDl09GvODH/nV1uOVtNqxHsNlvF/Zi1qPFwvJdq26YtZabcz8KYuQyn7kM0hZj+vSerE/Ei7jPa5pPfY+rnG8MTsekBazV7IDdkU/8pmQhKzHf1paf8JlXDncFa3HfiImgzzD3CmtXz8uSsh67E90CJ9tPYbLeI9rWo8zbaz6hMc6hNn6yH3Vj1zlOdbjEO1qGuOE9VgUuIx3uZ71ODMdh1kKPbqfly1m3bz1+shz9Bs/8s6n9gTrsZ/ol9ZjWRqZfG8WWI/v4CrWY1kgrZ+A9fgsV7EeCwNpASACpAWACJAWACJAWgCIAGkBIAKkBYAIkBYAIkBaAIgAaQEgAqQFgAiQFgAi/ANXHrcXSrXqoAAAAABJRU5ErkJggg==" alt="" />

为什么Chirs在前面呢?难道又比较了Name的ASCII,这么智能?笔者认为是因为Chirs申明在前的缘故

那我把 Chirs 和 James 换个位置试试看

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIMAAABRCAIAAAB+CYIVAAAB2ElEQVR4nO3a0XKDIBBGYR6NR+fReuFMggu7rlj17/R8V5akts0JppCUWmuBAkqooIQKSqighApKqKCEik+J1lprzdzaOuP3euNYsZVYe8Qp8Ztqrf0DGsyMZ3+v/2ethDeHzo7j68qcMOPeeQ7Pj1K6EsHTdqHEeDemxYGb5kTm27HD1UlFXMK7sGT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+Nq4d0PiioQd8j/qCw5gNxyVrfZxHV5psSUTY6KZHa+VYiEdtRoIl9DmJp2kwhF6d6jJ+nstRl6waXmMKhqaiHY1o0JbJPdivAGvbm0cyMJQF5PFSeDDRR2MYFzWY6vOaYhtkyh6p0G6WP4cnN6/m6ORCbxSaKTT5yuaaDP5Sy3Qu5/l2Rnzg3cR6+DRKh9vb1LjVy3Je0OTUt/pH/RX4I9fz+gG8PqgrLJWUaHrUQcYl8QqnOa/6/Ki3gY71d7VKNS8QxcIk4Bi4Rx8Al4hi4RBwDl4hj8A/HvBvozQz0iwAAAABJRU5ErkJggg==" alt="" /> 这一步骤具体是如何实现的呢?笔者还没有彻底想通,233

那么我们在继续想,能否实现想比较姓名大小、年龄大小等,这些大小都可以比较,根据我选择不同来实现呢?

在Sort方法的重载里可以具体实现比较器 IComparer ,通过传入不同比较器来实现不同比较方式

class Person
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
} private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}
}
  
   //升序
class PersonSortByAgeAsc : IComparer
{
public int Compare(object x, object y)
{
Person p1 = x as Person;
Person p2 = y as Person;
if (p1 != null && p2 != null)
{
return p1.Age - p2.Age;
}
else
{
throw new ArgumentException();
}
}
} arr2.Sort(new PersonSortByAgeAsc());
    /// <summary>
/// 降序
/// </summary>
class PersonSortByAgeDesc : IComparer
{
public int Compare(object x, object y)
{
Person p1 = x as Person;
Person p2 = y as Person;
if (p1 != null && p2 != null)
{
return p2.Age - p1.Age;
}
else
{
throw new ArgumentException();
}
}
} arr.Sort(new PersonSortByAgeDesc()); //传入的参数不同, 比较方式不同,更加灵活多变,代码可塑性强! 让班长排序,我们直接提供了一台机器,这台机器即可根据自定义来选择排序方式(多态)