There is a class Contact with fields public int number and public string name I want to sort by name

 class Contact { public int number; public string name; } class Program { static void Main(string[] args) { int n = 250; string t = ""; Contact[] ob = new Contact[n]; for (int i = 0; i < n; i++) { ob[i] = new Contact(); } 

Closed due to the fact that the essence of the issue is incomprehensible by the participants αλεχολυτ , Yuri , Mikhail Vaysman , ߊߚߤߘ , Vadizar 3 Mar '17 at 13:56 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

2 answers 2

For your case (array), you can, for example, like this:

 Array.Sort(contacts, (c1, c2) => c1.name.CompareTo(c2.name)); 

    As one of the options:

     ob = ob.OrderBy(c => c.name).ToArray();