Удаление элемента списка/вывод нового списка - C#
Формулировка задачи:
В общем, в 3м массиве у меня по идее должен был собраться новый список но выводится он чего-то не хочет по нормальному.
А во 2м пытаюсь удалить один их элементов но Equals и != ему почему-то не нравятся.
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. udalenie elementa massiva
3. Poisk po aviakompanii
");
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, };
fligths[1] = new AirplanesProperties { number = 2, arrivalTime = y, };
fligths[2] = new AirplanesProperties { number = 3, arrivalTime = z, };
fligths[3] = new AirplanesProperties { number = 4, arrivalTime = k, };
Array.Sort(fligths);
System.Console.WriteLine(fligths);
}
#endregion
// udalenie elementa massiva
#region shippingFlight
private static void ShippingFlight()
{
List<AirplanesProperties> fligth = new List<AirplanesProperties>();
fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 3, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
// int n;
//n=Convert.ToInt32(Console.ReadLine());
//по индексу
fligth = fligth.Where((number, n) => n != 0).ToArray();
//вообще всё не нравится
//удаление по значению
fligth = fligth.Where(n => !n.Equals.fligth.ElementAt(del).ToArray());
Console.WriteLine(string.Join(" ", fligth.Select(x => x.ToString()).ToArray()));
//проблема в Equals
//или так,
fligth = fligth.Where(n => fligth.ElementAt(del) != n).ToArray();
//матюкается на !=
}
#endregion
//Poisk po aviakompanii
#region gate
private static void gate()
{
string z;
Console.WriteLine("set the airline to found");
z = Convert.ToString(Console.ReadLine());
List<AirplanesProperties> fligth = new List<AirplanesProperties>();
fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 3, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
List<AirplanesProperties> result = fligth.Where(x => x.airline == z).ToList();
Console.WriteLine(fligth);
}
#endregion
}
}
}Решение задачи: «Удаление элемента списка/вывод нового списка»
textual
Листинг программы
int n = Convert.ToInt32(Console.ReadLine()); fligth = fligth.Where(x => x.number != n).ToList <AirplanesProperties>();