Advertisement
NPSF3000

C# List Sort

Oct 17th, 2011
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace SortList
  7. {
  8.     class Program
  9.     {
  10.         struct Weapon
  11.         {
  12.             public int DPS;
  13.             public Weapon(int DPS)
  14.             {
  15.                 this.DPS = DPS;
  16.             }
  17.         }
  18.  
  19.         static List<Weapon> weapons = new List<Weapon>(100);
  20.         static void Main(string[] args)
  21.         {
  22.             var rnd = new Random();
  23.             for (int i = 0; i < 100; i++)
  24.                 weapons.Add(new Weapon(rnd.Next(100)));
  25.  
  26.             //weapons.Sort((w1, w2) => w2.DPS.CompareTo(w1.DPS));
  27.             weapons.Sort((w1, w2) => w2.DPS - w1.DPS);
  28.  
  29.             weapons.ForEach(x => Console.WriteLine(x.DPS));
  30.             Console.ReadLine();
  31.         }
  32.     }
  33. }
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement