Dziedziczenie klasy posiadajacej deklaracje listy i brak oddania wynikow

0

Mam problem taki, że moja lista jest w innej klasie i ją z niej dziedziczę do innej( elementy dodają się do listy bez problemowo, ale są widoczne tylko z tej klasy dodaj)
gdy próbuje wywołać te ów elementy z innej klasy to już ich nie widać. Jakieś pomysły dlaczego ?

w skrocie klasy : dodaj, lista i wywołaj
dodaj -dziedziczy z lista
wywolaj- dziedziczy z lista
klasa lista -jest abstrakcyjna
ale po uzyciu dodaj, nie są one nigdzie zapisywane i znikaja lub nie sa przekazywane do klasy lista

Moje oczekiwania ingerowanie w liste w klasie lista z roznych klas.

  class Lista
    {

        public List<Samochod> list = new List<Samochod>();

        public void wypis()
        {
//nie wypisuje
            foreach (var item in list)
            {
                Console.WriteLine(item.Model + item.Rocznik + item.Silnik);
            }

        }

 class Dodaj_auto : Lista
    {
//po dodaniu wypisuje je bezproblemowo 

        public void dodaj()
        {
            Console.WriteLine("ile samochodow ");
            int x = int.Parse(Console.ReadLine());
            var samochody = new Samochod[x];
            


            for (int i = 0; i < x; i++)
            {
                Console.WriteLine($"samochod {i + 1} ");

                Console.WriteLine("marka");
                string y = Console.ReadLine();

                Console.WriteLine("rocznik");


                int z = int.Parse(Console.ReadLine());
                Console.WriteLine("silnik");



                double q = double.Parse(Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);






                samochody[i] = new Samochod(y, z, q);



                list.Add(samochody[i]);
                // Samochod s[i] = new Samochod(y, z, q);


            }

            

        }






    }



class Samochod 

    {
        private int rocznik;
        private double silnik;

        public string Model{ get; set; }
        public int Rocznik 
        {
            get
            {
                return rocznik;
            }

            set 
            {
                if (value < 1900 || value > 2021)
                {
                }
                else
                {
                    rocznik = value;
                }
            } 
        }
        public double Silnik
        {
            get
            {
                return silnik;
            }

            set
            {
                if (value < 0.1 || value > 9.9)
                {
                }
                else
                {
                    silnik = value;
                }
            }
        }



        public Samochod(string Model, int Rocznik, double Silnik)
        {
            this.Model = Model;
            this.Rocznik = Rocznik;
            this.Silnik = Silnik;

        
        
        }
}






1

Po pierwsze to te twoje dziedziczenie jest kompletnie bez sensu.
Po drugie, wołasz w ogole tę metodę wypis() ? bo jak ją zawołasz to wypisze, jak nie zawołasz to nie wypisze :D
Po trzecie, zaprzyjaźnij się z debuggerem, breakpointami, to jest 10 minut zeby ogarnąć na podstawowym poziomie, nie bedziesz musial zakladać takich tematów.

0

Dopiero się uczę ^^
Tak wołam, ale ta metoda jest tylko do sprawdzenia. W innej klasie napisałem kod sortujący i filtrujący tablice i to z niej chciałbym wywołać.
Czy mógłbyś mi pomoc to poprawić i pokazać jak powinno byc poprawnie ?
Postaram sie zastosowac w jutrzejszym dniu ze wskazówki debugera.

0

Mogę Ci pomóc, ale pokaż caly kod i napisz konkretnie co nie działa.

0

To caly kod. Nie moge zaingerowac w liste w klasie lista po przez klase usun czy dodaj.
Domyslalam sie, ze powinienem przez get set, ale przyznam szczerze, ze nie wiemjak.
(wszystko sie kompiluje, lecz nie widzi tego co dodalem przez klase dodaj w innych klasach. Z tego co sprawdziłem nie zapisuje mi tego nawet w klasie lista.)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lekcja_17_komis_samo
{
    class Program
    {
        static void Main(string[] args)
        {




            Dodaj_auto dodaj_Auto = new Dodaj_auto();
            Lista lista = new Lista();

            Wypisz sortowanie_wypisywanie = new Wypisz();

            usun_auto usun = new usun_auto();

            


        start:


            for (int i = 0; i < 5;)
            {







                Console.WriteLine("  wybierz: \n 1-dodaj\n 2-usun\n 3-znajdz\n 4-wypisz\n 5-wyjdz ");
                int liczba = int.Parse(Console.ReadLine());
                i = liczba;

                switch (liczba)
                {

                    case 1:
                        //dodaj
                        dodaj_Auto.dodaj();


                        break;
                    case 2:

                        //Usun

                        usun.usun();




                        break;
                    case 3:


                        // Znajdz
                        break;
                    case 4:
                        //Wypisz

                        Console.WriteLine($"1. Sortuj alfabetycznie \n 2.Sortuj malejono silniki\n 3.Sortuj rosnaco silniki \n 4. Sortuj malejąco rocznik \n 5. Sortuj rosnaco rocznik \n 6.Cofnij  ");
                        int sort = int.Parse(Console.ReadLine());





                        for (; sort < 7;)
                        {
                            Console.WriteLine($"1. Sortuj alfabetycznie \n 2.Sortuj malejono silniki\n 3.Sortuj rosnaco silniki \n 4. Sortuj malejąco rocznik \n 5. Sortuj rosnaco rocznik \n 6.Cofnij  ");


                            sort = int.Parse(Console.ReadLine());





                            switch (sort)
                            {
                                case 1:
                                    sortowanie_wypisywanie.marki_alfabetycznie();

                                    break;
                                case 2:
                                    sortowanie_wypisywanie.Pojemnosc_malejaco();

                                    break;
                                case 3:
                                    sortowanie_wypisywanie.Pojemnosc_rosnaco();

                                    break;
                                case 4:
                                    sortowanie_wypisywanie.Rocznik_malejaco();
                                    break;
                                case 5:
                                    sortowanie_wypisywanie.Rocznik_rosnaco();

                                    break;
                                case 6:

                                    //cofnij


                                    goto start;


                            }


                        }

                        break;
                    case 5:

                        Console.WriteLine("DOZOBACZENIA !!!");
                        // Wyjdz
                        break;

                }

            }

            Console.ReadKey();

        }
    }
class Lista
    {


               public List<Samochod> list = new List<Samochod>();



    }


class Dodaj_auto : Lista
    {
        
        public void dodaj()
        {
            Console.WriteLine("ile samochodow ");
            int x = int.Parse(Console.ReadLine());
            var samochody = new Samochod[x];
            


            for (int i = 0; i < x; i++)
            {
                Console.WriteLine($"samochod {i + 1} ");

                Console.WriteLine("marka");
                string y = Console.ReadLine();

                Console.WriteLine("rocznik");


                int z = int.Parse(Console.ReadLine());
                Console.WriteLine("silnik");



                double q = double.Parse(Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);






                samochody[i] = new Samochod(y, z, q);



              list.Add(samochody[i]);
                // Samochod s[i] = new Samochod(y, z, q);

                
            }

            

        }






    }


 class Samochod //: IComparable

    {
        private int rocznik;
        private double silnik;

        public string Model{ get; set; }
        public int Rocznik 
        {
            get
            {
                return rocznik;
            }

            set 
            {
                if (value < 1900 || value > 2021)
                {
                }
                else
                {
                    rocznik = value;
                }
            } 
        }
        public double Silnik
        {
            get
            {
                return silnik;
            }

            set
            {
                if (value < 0.1 || value > 9.9)
                {
                }
                else
                {
                    silnik = value;
                }
            }
        }



        public Samochod(string Model, int Rocznik, double Silnik)
        {
            this.Model = Model;
            this.Rocznik = Rocznik;
            this.Silnik = Silnik;

        
        
        }
}

 class SamochodComparer : IComparer<Samochod>
    {
        public int Compare(Samochod x, Samochod y)
        {
          

            if (x.Rocznik < y.Rocznik)
                return 1;
            else if (x.Rocznik == y.Rocznik)
                return 0;
            else
                return -1;






        }
    }
 class SamochodComparer_roczik_rosnaco : IComparer<Samochod>
    {
        public int Compare(Samochod x, Samochod y)
        {


            if (x.Rocznik > y.Rocznik)
                return 1;
            else if (x.Rocznik == y.Rocznik)
                return 0;
            else
                return -1;






        }
    }

  class SamochodComparer_silnik : IComparer<Samochod>
    {
        public int Compare(Samochod x, Samochod y)
        {


            if (x.Silnik < y.Silnik)
                return 1;
            else if (x.Silnik == y.Silnik)
                return 0;
            else
                return -1;






        }
    }
 class SamochodComparer_silnik_malejaco : IComparer<Samochod>
    {
        public int Compare(Samochod x, Samochod y)
        {


            if (x.Silnik > y.Silnik)
                return 1;
            else if (x.Silnik == y.Silnik)
                return 0;
            else
                return -1;






        }



    }
 class usun_auto : Lista
    {


        public void usun()
        {

            
            int i = 0;

            foreach (var item in list)
            {
                

                Console.WriteLine(i + ". " + item.Model + "- | -" + item.Rocznik + "  ||| pojemnosc - | " + item.Silnik);

                i++;

            }

            
            Console.WriteLine("Ktory elemet listy usunac ?");

            int x = int.Parse(Console.ReadLine());


            list.RemoveAt(x);
        
        
        
        }


}




0

No nie masz takiej klasy Wypisz , wiec jak chcesz utworzyc jej instancje?

0

oj, nie skopiowałem klasy jednej

  class Wypisz : Lista
    {

        public void Rocznik_rosnaco()
        {

            list.Sort(new SamochodComparer_roczik_rosnaco());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Rocznik + "  ||| pojemnosc - | " + item.Silnik);


            }


        }


        public void Rocznik_malejaco()
        {

            list.Sort(new SamochodComparer());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Rocznik + "  ||| pojemnosc - | " + item.Silnik);


            }


        }

        public void Pojemnosc_rosnaco()
        {

            list.Sort(new SamochodComparer_silnik());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Rocznik + "  ||| pojemnosc - | " + item.Silnik);


            }


        }


        public void Pojemnosc_malejaco()
        {

            list.Sort(new SamochodComparer_silnik_malejaco());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Rocznik + "  ||| pojemnosc - | " + item.Silnik);


            }


        }

        public void marki_alfabetycznie()
        {


            list.Sort();

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Rocznik + "  ||| pojemnosc - | " + item.Silnik);


            }


        }







    }
0

Zobacz ten przykład który jest widoczny u Ciebie w kodzie:

        class Lista
        {
            public List<int> list { get; set; }
        }
        class Wypisz : Lista
        {
            // Tutaj jest inna lista
        }
        class Dodaj_auto : Lista
        {
            // I tutaj jest inna lista
        }

Popełniasz tutaj kilka błędów:

  1. Takie operacje jak wypisz, dodaj, usuń powinny być metodami, nie klasami. Klasa powinna być obiektem na przykład samochód, osoba
  2. Operacje dodaj / usuń / wypisz powinieneś umieścić w klasie Lista
  3. Dziedziczenie nie jest tu potrzebne. Wystarczy zrobić to w taki sposób:
class ListaSamochodow
        {
            private List<samochod> list = new List<samochod>();
            public void Add(samochod samochod) { }
            public enum eSortType
            {
                rocznik = 0,
                pojemnosc = 1,
            }
            public IEnumerable<samochod> SortBy(eSortType sortType) { }
            public void Wypisz() { }
        }

I przykładowe użycie:

ListaSamochodow lista = new ListaSamochodow();
lista.Wypisz();
lista.SortBy(ListaSamochodow.eSortType.rocznik);
2

Twoje samochody sa w klasie Dodaj_auto. a ty wypisujesz samochody z klasy Wypisz. To ze obie klasy dziedzicza z Lista, nie znaczy ze wspoldziela stan. Chyba ze jest statyczny. Daj statica tutaj

class Lista
    {
        public static List<Samochod> list = new List<Samochod>();
    }

To cos ci sie powinno udać wyswietlic.
Ale na twoim miejscu byl to zaorał i napisał bez dziedziczenia.

0

Oczywiście dodanie static pomogło, jak przewidywałeś.
Zgodnie ze wskazówkami przerobiłem swój kod i staram się nauczyć jak najbardziej poprawnego jego pisania. Chciałbym byście zobaczyli i ponownie dali mi kilka wskazówek. Chciałbym zaznaczyć, że metoda sort znów nie działa.

Chciałbym dowiedzieć się również co robi ta funkcja i w jaki sposób działa:

   public enum eSortType
        {
            rocznik = 0,
            pojemnosc = 1,
        }
        public IEnumerable<samochod> SortBy(eSortType sortType) { }

Oto mój kod:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KomisSamochodowy_poprawiony
{
    class Program
    {
        static void Main(string[] args)
        {

            Menu main = new Menu();




            Console.ReadKey();
        }
    }

 class Menu
    {
        CarList sort = new CarList();
        CarList add = new CarList();
        CarList delete = new CarList();



        public Menu()
        {




        start:


            for (int i = 0; i < 5;)
            {


                Console.WriteLine("  wybierz: \n 1-dodaj\n 2-usun\n 3-znajdz\n 4-wypisz\n 5-wyjdz ");
                int liczba = int.Parse(Console.ReadLine());
                i = liczba;

                switch (liczba)
                {

                    case 1:
                        //dodaj
                        add.AddCar();


                        break;
                    case 2:


                        delete.DeleteCar();
                        //Usun






                        break;
                    case 3:


                        // Znajdz
                        break;
                    case 4:
                        //Wypisz

                        Console.WriteLine($"1. Sortuj alfabetycznie \n 2.Sortuj malejono silniki\n 3.Sortuj rosnaco silniki \n 4. Sortuj malejąco rocznik \n 5. Sortuj rosnaco rocznik \n 6.Cofnij  ");
                        int sorte = int.Parse(Console.ReadLine());





                        for (; sorte < 7;)
                        {
                            Console.WriteLine($"1. Sortuj alfabetycznie \n 2.Sortuj malejono silniki\n 3.Sortuj rosnaco silniki \n 4. Sortuj malejąco rocznik \n 5. Sortuj rosnaco rocznik \n 6.Cofnij  ");


                            sorte = int.Parse(Console.ReadLine());





                            switch (sorte)
                            {
                                case 1:
                                    sort.ModelAlphabetically();
                                    break;
                                case 2:
                                    sort.DescendingEngine();

                                    break;
                                case 3:
                                    sort.AscendinglyEngine();
                                    break;
                                case 4:
                                    sort.DescendingVintage();
                                    break;
                                case 5:
                                    sort.AscendinglyVintage();

                                    break;
                                case 6:

                                    //cofnij


                                    goto start;


                            }


                        }

                        break;
                    case 5:

                        Console.WriteLine("DOZOBACZENIA !!!");
                        // Wyjdz
                        break;

                }

            }










        }
    }


 class CarList
    {
        private List<Car> list = new List<Car>();
        public void AddCar() 
        {
            Console.WriteLine("ile samochodow ");
            int x = int.Parse(Console.ReadLine());
            var cars = new Car[x];



            for (int i = 0; i < x; i++)
            {
                Console.WriteLine($"samochod {i + 1} ");

                Console.WriteLine("marka");
                string y = Console.ReadLine();

                Console.WriteLine("rocznik");


                int z = int.Parse(Console.ReadLine());
                Console.WriteLine("silnik");



                double q = double.Parse(Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);






                cars[i] = new Car(y, z, q);



                list.Add(cars[i]);
                // Samochod s[i] = new Samochod(y, z, q);


            }



        }


        public void DeleteCar()
        {

            int i = 0;

            foreach (var item in list)
            {


                Console.WriteLine(i + ". " + item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);

                i++;

            }


            Console.WriteLine("Ktory elemet listy usunac ?");

            int x = int.Parse(Console.ReadLine());


            list.RemoveAt(x);



        }



        //public enum eSortType
        //{
        //    rocznik = 0,
        //    pojemnosc = 1,
        //}
        //public IEnumerable<Car> SortBy(eSortType sortType) 
        //{ 








        //}
        //public void Wypisz() { 




        //}

        public void AscendinglyVintage()
        {

            list.Sort(new CarComparerAscendinglyVintage());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }


        public void DescendingVintage()
        {

            list.Sort(new CarComparerDescendingVintage());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }

        public void AscendinglyEngine()
        {

            list.Sort(new CarComparerAscendinglyEngine());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }


        public void DescendingEngine()
        {

            list.Sort(new CarComparerDescendingEngine());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }

        public void ModelAlphabetically()
        {


            list.Sort();

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }







    }



 class CarComparerDescendingVintage : IComparer<Car>
    {
        public int Compare(Car x, Car y)
        {


            if (x.Vintage > y.Vintage)
                return 1;
            else if (x.Vintage == y.Vintage)
                return 0;
            else
                return -1;


        }

    }
class CarComparerDescendingEngine : IComparer<Car>
    {
        public int Compare(Car x, Car y)
        {


            if (x.Engine > y.Engine)
                return 1;
            else if (x.Engine == y.Engine)
                return 0;
            else
                return -1;


        }



    }

 class CarComparerAscendinglyVintage : IComparer<Car>
    {
        public int Compare(Car x, Car y)
        {


            if (x.Vintage < y.Vintage)
                return 1;
            else if (x.Vintage == y.Vintage)
                return 0;
            else
                return -1;


        }

    }

class CarComparerAscendinglyEngine : IComparer<Car>
    {
        public int Compare(Car x, Car y)
        {


            if (x.Engine < y.Engine)
                return 1;
            else if (x.Engine == y.Engine)
                return 0;
            else
                return -1;


        }

    }
class Car
    {
        
            private int vintage;
            private double engine;

            public string Model { get; set; }
            public int Vintage
            {
                get
                {
                    return vintage;
                }

                set
                {
                    if (value < 1900 || value > 2021)
                    {
                    }
                    else
                    {
                        vintage = value;
                    }
                }
            }
            public double Engine
            {
                get
                {
                    return engine;
                }

                set
                {
                    if (value < 0.1 || value > 9.9)
                    {
                    }
                    else
                    {
                        engine = value;
                    }
                }
            }



            public Car(string Model, int Vintage, double Engine)
            {
                this.Model = Model;
                this.Vintage = Vintage;
                this.Engine = Engine;



            }




        }

}
1

Popełniasz dalej ten sam błąd który wspomniałem w poprzedniej odpowiedzi:
screenshot-20210322120521.png

CarList to lista samochodów, więc dlaczego nazywasz ją "sort" lub "delete" ? To nie ma żadnego sensu. Nazwij ją lista1, lista2, lista3 i zobaczysz od razu błąd. Jak dodasz element do lista1 i posortujesz lista2 to nie ma sensu, bo lista2 dalej jest pusta (bo dodałeś element do lista1). Popraw to i wklej kod. Przeczytaj zalecenia w mojej poprzedniej odpowiedzi i nie idź na skróty.

Czerwone strzałki określają na jakiej liście zostaną wykonane operacje w metodach w konkretnej instancji klasy:
Czy to ma jakiś sens?

            sort.AddCar();
            sort.DeleteCar();
            add.DeleteCar();
            delete.SortBy();

i jeszcze jedno, w jaki sposób static Ci pomogło, skoro nawet tego nie zrobiłeś?

0

Dobra, zrozumiałem swój błąd po zmianie nazwy na list1, list2,list3. Wszystko zaczęło poprawnie działać użyciu tylko jednej listy.
Co do static nie mam pojecia jak, ale gdy tylko dodałem go do poprzedniego kodu to o dziwo jakoś czytało to jako jedną listę.

W razie jakiś błędów myślowych lub typowo obiektowych proszę o wskazówkę.

Wracam jeszcze do pytania
"
Chciałbym dowiedzieć się również co robi ta funkcja i w jaki sposób działa:
"

 public enum eSortType
        {
           rocznik = 0,
           pojemnosc = 1,
      }
 public IEnumerable<samochod> SortBy(eSortType sortType) { }> 
0

A pokaż kod który masz aktualnie

0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KomisSamochodowy_poprawiony
{
    class Program
    {
        static void Main(string[] args)
        {

            Menu main = new Menu();




            Console.ReadKey();
        }
    }
 class Menu
    {
        // praca na jednej liscie
        CarList lista1 = new CarList();

        //CarList lista2 = new CarList();
       // CarList lista3 = new CarList();



        public Menu()
        {




        start:


            for (int i = 0; i < 5;)
            {


                Console.WriteLine("  wybierz: \n 1-dodaj\n 2-usun\n 3-znajdz\n 4-wypisz\n 5-wyjdz ");
                int liczba = int.Parse(Console.ReadLine());
                i = liczba;

                switch (liczba)
                {

                    case 1:
                        //dodaj
                        lista1.AddCar();


                        break;
                    case 2:


                        lista1.DeleteCar();
                        //Usun






                        break;
                    case 3:


                        // Znajdz
                        break;
                    case 4:
                        //Wypisz

                        Console.WriteLine($"1. Sortuj alfabetycznie \n 2.Sortuj malejono silniki\n 3.Sortuj rosnaco silniki \n 4. Sortuj malejąco rocznik \n 5. Sortuj rosnaco rocznik \n 6.Cofnij  ");
                        int sorte = int.Parse(Console.ReadLine());





                        for (; sorte < 7;)
                        {
                            Console.WriteLine($"1. Sortuj alfabetycznie \n 2.Sortuj malejono silniki\n 3.Sortuj rosnaco silniki \n 4. Sortuj malejąco rocznik \n 5. Sortuj rosnaco rocznik \n 6.Cofnij  ");


                            sorte = int.Parse(Console.ReadLine());





                            switch (sorte)
                            {
                                case 1:
                                    lista1.ModelAlphabetically();
                                    break;
                                case 2:
                                    lista1.DescendingEngine();

                                    break;
                                case 3:
                                    lista1.AscendinglyEngine();
                                    break;
                                case 4:
                                    lista1.DescendingVintage();
                                    break;
                                case 5:
                                    lista1.AscendinglyVintage();

                                    break;
                                case 6:

                                    //cofnij


                                    goto start;


                            }


                        }

                        break;
                    case 5:

                        Console.WriteLine("DOZOBACZENIA !!!");
                        // Wyjdz
                        break;

                }

            }










        }
    }

 class CarList
    {
        private List<Car> list = new List<Car>();
        public void AddCar() 
        {
            Console.WriteLine("ile samochodow ");
            int x = int.Parse(Console.ReadLine());
            var cars = new Car[x];



            for (int i = 0; i < x; i++)
            {
                Console.WriteLine($"samochod {i + 1} ");

                Console.WriteLine("marka");
                string y = Console.ReadLine();

                Console.WriteLine("rocznik");


                int z = int.Parse(Console.ReadLine());
                Console.WriteLine("silnik");



                double q = double.Parse(Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);






                cars[i] = new Car(y, z, q);



                list.Add(cars[i]);
                // Samochod s[i] = new Samochod(y, z, q);


            }



        }


        public void DeleteCar()
        {

            int i = 0;

            foreach (var item in list)
            {


                Console.WriteLine(i + ". " + item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);

                i++;

            }


            Console.WriteLine("Ktory elemet listy usunac ?");

            int x = int.Parse(Console.ReadLine());


            list.RemoveAt(x);



        }



        //public enum eSortType
        //{
        //    rocznik = 0,
        //    pojemnosc = 1,
        //}
        //public IEnumerable<Car> SortBy(eSortType sortType) 
        //{ 








        //}
        //public void Wypisz() { 




        //}

        public void AscendinglyVintage()
        {

            list.Sort(new CarComparerAscendinglyVintage());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }


        public void DescendingVintage()
        {

            list.Sort(new CarComparerDescendingVintage());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }

        public void AscendinglyEngine()
        {

            list.Sort(new CarComparerAscendinglyEngine());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }


        public void DescendingEngine()
        {

            list.Sort(new CarComparerDescendingEngine());

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }

        public void ModelAlphabetically()
        {


            list.Sort();

            foreach (var item in list)
            {

                Console.WriteLine(item.Model + "- | -" + item.Vintage + "  ||| pojemnosc - | " + item.Engine);


            }


        }







    }

 class CarComparerDescendingVintage : IComparer<Car>
    {
        public int Compare(Car x, Car y)
        {


            if (x.Vintage > y.Vintage)
                return 1;
            else if (x.Vintage == y.Vintage)
                return 0;
            else
                return -1;


        }

    }

class CarComparerDescendingEngine : IComparer<Car>
    {
        public int Compare(Car x, Car y)
        {


            if (x.Engine > y.Engine)
                return 1;
            else if (x.Engine == y.Engine)
                return 0;
            else
                return -1;


        }



    }
 class CarComparerAscendinglyVintage : IComparer<Car>
    {
        public int Compare(Car x, Car y)
        {


            if (x.Vintage < y.Vintage)
                return 1;
            else if (x.Vintage == y.Vintage)
                return 0;
            else
                return -1;


        }

    }
class CarComparerAscendinglyEngine : IComparer<Car>
    {
        public int Compare(Car x, Car y)
        {


            if (x.Engine < y.Engine)
                return 1;
            else if (x.Engine == y.Engine)
                return 0;
            else
                return -1;


        }

    }
class Car
    {
        
            private int vintage;
            private double engine;

            public string Model { get; set; }
            public int Vintage
            {
                get
                {
                    return vintage;
                }

                set
                {
                    if (value < 1900 || value > 2021)
                    {
                    }
                    else
                    {
                        vintage = value;
                    }
                }
            }
            public double Engine
            {
                get
                {
                    return engine;
                }

                set
                {
                    if (value < 0.1 || value > 9.9)
                    {
                    }
                    else
                    {
                        engine = value;
                    }
                }
            }



            public Car(string Model, int Vintage, double Engine)
            {
                this.Model = Model;
                this.Vintage = Vintage;
                this.Engine = Engine;



            }




        }



}
0

@Michał Skóra:

Chciałbym dowiedzieć się również co robi ta funkcja i w jaki sposób działa:
"

 public enum eSortType
        {
           rocznik = 0,
           pojemnosc = 1,
      }
 public IEnumerable<samochod> SortBy(eSortType sortType) { }> 

no więc patrząc na kod można z całą pewnością stwierdzić że ta funkcja nic nie robi i nie działa, a nawet nie istnieje ponieważ nie ma implementacji i jest zakomentowana

0

Poczytaj sobie o tym enum (pierwsze 5 linków z google po wpisaniu "enum")
https://docs.microsoft.com/pl-pl/dotnet/csharp/language-reference/builtin-types/enum
https://docs.microsoft.com/pl-pl/dotnet/api/system.enum?view=net-5.0
https://www.w3schools.com/cs/cs_enums.asp
https://www.tutorialsteacher.com/csharp/csharp-enum
https://www.plukasiewicz.net/Artykuly/CSharpHandlingEnums

Tutaj masz opis metody. Dzięki niej wszystkie sortowania będą łatwe w użyciu. Musisz tylko dokończyć metodę:

        public enum eSortType
        {
            rocznik = 0,
            pojemnosc = 1,
        }
        /// <summary>
        /// Zwraca posortowaną listę według parametru <paramref name="sortType"/>
        /// </summary>
        /// <param name="sortType">Dane na podstawie których nastąpi sortowanie</param>
        /// <returns>Zwraca posortowaną listę</returns>
        public IEnumerable<samochod> SortBy(eSortType sortType)
        {
            switch(sortType)
            {

            }
        }

1 użytkowników online, w tym zalogowanych: 0, gości: 1