В массиве выполнить поиск по параметру - C#

Узнай цену своей работы

Формулировка задачи:

нужно в 3 массиве выполнить поиск по параметру airline
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication19
{
    class Program
    {
        enum FlightType
        {
            flights,
        }
 
        struct AirplanesProperties
        {
            public int number;
            public string city;
            public string airline;
            public int terminal;
            public int arrivalTime;
            public int shippingFlight;
            public int bgate;

           static void Main(string[] args)
            {
                long a;
                Console.WriteLine(@"Please,  type the number:
            1. arrivalTime1
            2. ShippingFlight
            3. state of gate
            ");
 
                a = long.Parse(Console.ReadLine());
                switch (a)
                {
                    case 1:
                        Arrivaltime1();
                        Console.WriteLine("");
                        break;

                    case 2:
 
                        ShippingFlight();
                        Console.WriteLine("");
                        break;
 
                    case 3:
 
                        gate();
                        Console.WriteLine("");
                        break;
                    default:
                        Console.WriteLine("Exit");
                        break;
 
                }
                Console.WriteLine("Press any key");
                Console.ReadLine();
            }

            #region ArrivalTime1        
            private static void Arrivaltime1()
            {
                int x;
                int y;
                int z;
                int k;
 
                Console.WriteLine("arrivalTime1");
                x = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("arrivalTime2");
                y = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("arrivalTime3");
                z = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("arrivalTime4");
                k = Convert.ToInt32(Console.ReadLine());
 
                AirplanesProperties[] fligths = new AirplanesProperties[4];
                fligths[0] = new AirplanesProperties { number = 1, arrivalTime = x, city = "Kiev", airline = "MAU", terminal = 1 };
                fligths[1] = new AirplanesProperties { number = 2, arrivalTime = y, city = "Odessa", airline = "MAU", terminal = 2 };
                fligths[2] = new AirplanesProperties { number = 3, arrivalTime = z, city = "Odessa", airline = "MAU", terminal = 2 };
                fligths[3] = new AirplanesProperties { number = 4, arrivalTime = k, city = "Odessa", airline = "MAU", terminal = 4 };
 
                Array.Sort(fligths);
 
                System.Console.WriteLine(fligths);

            }
            #endregion
            #region shippingFlight
            private static void ShippingFlight()
            {
                int x;
                int y;
                int z;
                int k;

                Console.WriteLine("shipping flight1");
                x = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("shipping flight2");
                y = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("shipping flight3");
                z = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("shipping flight4");
                k = Convert.ToInt32(Console.ReadLine());
 
                AirplanesProperties[] fligths = new AirplanesProperties[4];
                fligths[0] = new AirplanesProperties { number = 1, shippingFlight = x, city = "Kiev", airline = "MAU", terminal = 1 };
                fligths[1] = new AirplanesProperties { number = 2, shippingFlight = y, city = "Odessa", airline = "MAU", terminal = 2 };
                fligths[2] = new AirplanesProperties { number = 3, shippingFlight = z, city = "Odessa", airline = "MAU", terminal = 2 };
                fligths[3] = new AirplanesProperties { number = 4, shippingFlight = k, city = "Odessa", airline = "MAU", terminal = 4 };

                Array.Clear(fligths, 0 , 1 );
 
                for (int i = 0; i < 4; i++)
                {
                    Console.Write("{0} ", fligths[i]);
                }
                Console.WriteLine();
                Console.WriteLine();

            }
            #endregion
            #region gate
            private static void gate()
            {
                int x;
                int y;
                int z;
                int k;
           
                Console.WriteLine("shipping flight1");
                x = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("shipping flight2");
                y = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("shipping flight3");
                z = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("shipping flight4");
                k = Convert.ToInt32(Console.ReadLine());
 
                AirplanesProperties[] fligths = new AirplanesProperties[4];
                fligths[0] = new AirplanesProperties { number = 1, bgate = x, city = "Kiev", airline = "MAU", terminal = 1 };
                fligths[1] = new AirplanesProperties { number = 2, bgate = y, city = "Odessa", airline = "MAU", terminal = 2 };
                fligths[2] = new AirplanesProperties { number = 3, bgate = z, city = "Odessa", airline = "MAU", terminal = 2 };
                fligths[3] = new AirplanesProperties { number = 4, bgate = k,city = "Odessa", airline = "MAU", terminal = 4 };

            }
            #endregion
        }
    }
}

Решение задачи: «В массиве выполнить поиск по параметру»

textual
Листинг программы
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication19
{
    class Program
    {
        struct AirplanesProperties
        {
            public int number;
            public string city;
            public string airline;
            public int terminal;
            public int arrivalTime;
            public int shippingFlight;
            public int bgate;
        }
        public static void Main()
        {
            List<AirplanesProperties> APList = new List<AirplanesProperties>();
            APList.Add(new AirplanesProperties { number = 1, city = "Куала-Лумпур", airline = "Malaysia Airlines", terminal = 5,arrivalTime=0,shippingFlight=0,bgate=1 });
            APList.Add(new AirplanesProperties { number = 1, city = "Амстердам", airline = "Malaysia Airlines", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
            APList.Add(new AirplanesProperties { number = 1, city = "Москва", airline = "H***o Airlines", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
            List<AirplanesProperties> result = APList.Where(x => x.airline == "Malaysia Airlines").ToList();     // в этом спике будут все объекты типа AirplanesProperties из списка APList, у которых airline == Malaysia Airlines
        }
    }
}

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

12   голосов , оценка 4.083 из 5
Похожие ответы