Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

c# Sorted List in Function

hi i want to make a sorted list in ShowSort function it shows randomly i want to sort numbers from smallest to largest pls help

private static void hatekleme(List<Hat> hatlar)
 {
   List<Islem> islem1 = new List<Islem>();
   islem1.Add(new Islem { Id = 1, Name = "tv ekranı", Time = 0, Time1 = 0, Time2 = 0, Time3 = 0 });
   islem1.Add(new Islem { Id = 2, Name = "tv kasası ", Time = 0, Time1 = 0, Time2 = 0, Time3 = 0 });
   islem1.Add(new Islem { Id = 3, Name = "tv vidas", Time = 0, Time1 = 0, Time2 = 0, Time3 = 0 });

   List<Islem> islem2 = new List<Islem>();
   islem2.Add(new Islem { Id = 1, Name = "iĹźlemci  ", Time = 0, Time1 = 0, Time2 = 0, Time3 = 0 });
   islem2.Add(new Islem { Id = 2, Name = "ram", Time = 0, Time1 = 0, Time2 = 0, Time3 = 0 });
   islem2.Add(new Islem { Id = 3, Name = "gpu", Time = 0, Time1 = 0, Time2 = 0, Time3 = 0 });

   hatlar.Add(new Hat { Id = 1, Name = "Tv Üretim Hattı", Islemler = islem1 });
   hatlar.Add(new Hat { Id = 2, Name = "Anakart üretim hattı", Islemler = islem2 });

 }

private static void ShowSort(Hat category)
 {
   foreach (var product in category.Islemler)
    {
    Console.WriteLine($"{product.Name} : {product.Time} sn.");
    }
     Console.WriteLine("");
  }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can easily sort items in a list by OrderBy:

private static void ShowSort(Hat category)
        {
            var sortedItems=category.Islemler.OrderBy(x => x.Time);
            foreach (var product in sortedItems)
            {
                Console.WriteLine($"{product.Name} : {product.Time} sn.");
            }
            Console.WriteLine("");
        }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading