Ejemplo n.º 1
0
        public void FillFromFile(List <string[]> fileContent)
        {
            System.Console.WriteLine("--- Termékek beolvasása ---");
            foreach (string[] row in fileContent)
            {
                string name             = row[0];
                int    constructionYear = int.Parse(row[1]);
                double performance      = double.Parse(row[2]);

                switch (row.Length)
                {
                case 3:
                    AddDevice(new HeatingDevice(name, constructionYear, performance));
                    break;

                case 4:
                    HeatPumpType type = (HeatPumpType)Enum.Parse(typeof(HeatPumpType), row[3]);
                    AddDevice(new HeatPump(name, constructionYear, performance, type));
                    break;

                case 5:
                    bool           isCondensing = bool.Parse(row[3]);
                    BoilerFunction function     = (BoilerFunction)Enum.Parse(typeof(BoilerFunction), row[4]);
                    AddDevice(new Boiler(name, constructionYear, performance, isCondensing, function));
                    break;

                default:
                    throw new Exception("Invalid row length");
                }
            }
            System.Console.WriteLine("--- Termékek beolvasva ---");
        }
Ejemplo n.º 2
0
        public int GetNumberOfHeatPumpsOfType(HeatPumpType type)  // szűréses feladat megoldása Linq csomaggal (Where, Select, ToList)
        {
            List <HeatPump> heatPumps = products
                                        .Where(p => p is HeatPump)  // leszűröm a listából a hőszivattyúkat
                                        .Select(p => p as HeatPump) // HeatPump típusra castolom őket
                                        .ToList();                  // elmentem az új HeatPump objektumaimat egy listába
            int result = heatPumps
                         .Where(hp => hp.Type == type)              // leszűröm azokat a hőszivattyúkat, amiknek megfelelő a típusa
                         .ToList()                                  // listát csinálok belőle
                         .Count;                                    // és végül a hossza érdekel

            return(result);
        }