fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. struct Obj
  6. {
  7.  
  8. public string value1;
  9. public int value2;
  10. }
  11. static void Main(string[] args)
  12. {
  13. string[] Products = new string[4] { "Meat", "Bread", "Milk", "Chocolate" };
  14. int[] Prices = new int[4] { 25, 4, 10, 16 };
  15. Obj[] objs = new Obj[4];
  16. for (int i = 0; i < 4; i++)
  17. Console.WriteLine(Products[i] + "\n" + Prices[i] + "\n\n");
  18. for (int i = 0; i < 4; i++)
  19. {
  20. objs[i] = new Obj();
  21. objs[i].value1 = Products[i];
  22. objs[i].value2 = Prices[i];
  23. }
  24. Array.Sort(objs, new Comparison<Obj>((a, b) => a.value2.CompareTo(b.value2)));
  25. for (int i = 0; i < 4; i++)
  26. {
  27.  
  28. Products[i] = objs[i].value1;
  29. Prices[i] = objs[i].value2;
  30. }
  31. for (int i = 0; i < 4; i++)
  32. Console.WriteLine(Products[i] + " " + Prices[i]);
  33. }
  34. }
Success #stdin #stdout 0s 131520KB
stdin
Standard input is empty
stdout
Meat
25


Bread
4


Milk
10


Chocolate
16


Bread 4
Milk 10
Chocolate 16
Meat 25