Exemple #1
0
        public void SortingCost()
        {
            var fileStream = new FileStream(@"text.txt", FileMode.Truncate);

            using var f = new StreamWriter(fileStream);
            Console.WriteLine("\n____________________________________________________________________________________________________________________________________\n");
            Console.WriteLine("Sorting by production cost: ");
            ComparingETC[] broth = new ComparingETC[ProductNumber.Length];
            for (int i = 0; i < ProductNumber.Length; i++)
            {
                broth[i] = new ComparingETC(ProductNumber[i], Title[i], Weight[i], ProductionCost[i], SellingPrice[i]);
            }
            Array.Sort(broth, new ComparingETC.SortByCost());
            Console.WriteLine(Heading);
            f.WriteLine(Heading);
            for (int i = 0; i < ProductNumber.Length; i++)
            {
                if (i == ProductionCost.Length - 1)
                {
                    f.Write(broth[i].Passport());
                }
                else
                {
                    f.WriteLine(broth[i].Passport());
                }
                Console.WriteLine(broth[i].Passport());
            }

            f.Close();
        }
Exemple #2
0
        public int CompareTo(object com)
        {
            ComparingETC c = (ComparingETC)com;

            if (this.Price > c.Price)
            {
                return(1);
            }
            if (this.Price < c.Price)
            {
                return(-1);
            }
            return(0);
        }
Exemple #3
0
            int IComparer.Compare(object ob1, object ob2)
            {
                ComparingETC c1 = (ComparingETC)ob1;
                ComparingETC c2 = (ComparingETC)ob2;

                if (c1.Cost > c2.Cost)
                {
                    return(1);
                }
                if (c1.Cost < c2.Cost)
                {
                    return(-1);
                }
                return(0);
            }