Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections;
  7.  
  8. namespace ConsoleApplication7
  9. {
  10.  
  11.  
  12. public class KoloroweLiczbyCalkowite : IComparable
  13. {
  14. private int liczba;
  15. private string kolor;
  16.  
  17.  
  18. public KoloroweLiczbyCalkowite(int l1, string k1)
  19. {
  20. this.liczba = l1;
  21. this.kolor = k1;
  22. }
  23.  
  24. public override string ToString()
  25. {
  26. return liczba.ToString() + " " + kolor;
  27. }
  28.  
  29. public int CompareTo(object obj)
  30. {
  31. KoloroweLiczbyCalkowite kolorowa = obj as KoloroweLiczbyCalkowite;
  32. return this.liczba.CompareTo(kolorowa.liczba);
  33. }
  34.  
  35. }
  36. class Program
  37. {
  38. static void Main(string[] args)
  39. {
  40. string s = String.Empty;
  41. string[] kolory = { "bialy", "czerwony", "zolty", "zielony", "czarny", "brazowy" };
  42. List<KoloroweLiczbyCalkowite> numList = new List<KoloroweLiczbyCalkowite>();
  43.  
  44. Random r = new Random();
  45.  
  46. for (int i=0; i<4; i++)
  47. {
  48. numList.Add(new KoloroweLiczbyCalkowite(r.Next(20), kolory[r.Next(5)]));
  49. }
  50.  
  51. foreach (KoloroweLiczbyCalkowite c in numList)
  52. {
  53. s += c.ToString() + " ";
  54. }
  55.  
  56. System.Console.WriteLine("Lista przed sortowaniem: {0}", s);
  57.  
  58. numList.Sort();
  59. s = string.Empty;
  60. for (int i = 0; i<numList.Count; i++)
  61. {
  62. s += numList[i].ToString() + " ";
  63. }
  64. System.Console.WriteLine("Lista przed sortowaniem: {0}", s);
  65.  
  66. Console.ReadKey();
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement