Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections;
- namespace ConsoleApplication7
- {
- public class KoloroweLiczbyCalkowite : IComparable
- {
- private int liczba;
- private string kolor;
- public KoloroweLiczbyCalkowite(int l1, string k1)
- {
- this.liczba = l1;
- this.kolor = k1;
- }
- public override string ToString()
- {
- return liczba.ToString() + " " + kolor;
- }
- public int CompareTo(object obj)
- {
- KoloroweLiczbyCalkowite kolorowa = obj as KoloroweLiczbyCalkowite;
- return this.liczba.CompareTo(kolorowa.liczba);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- string s = String.Empty;
- string[] kolory = { "bialy", "czerwony", "zolty", "zielony", "czarny", "brazowy" };
- List<KoloroweLiczbyCalkowite> numList = new List<KoloroweLiczbyCalkowite>();
- Random r = new Random();
- for (int i=0; i<4; i++)
- {
- numList.Add(new KoloroweLiczbyCalkowite(r.Next(20), kolory[r.Next(5)]));
- }
- foreach (KoloroweLiczbyCalkowite c in numList)
- {
- s += c.ToString() + " ";
- }
- System.Console.WriteLine("Lista przed sortowaniem: {0}", s);
- numList.Sort();
- s = string.Empty;
- for (int i = 0; i<numList.Count; i++)
- {
- s += numList[i].ToString() + " ";
- }
- System.Console.WriteLine("Lista przed sortowaniem: {0}", s);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement