如何通过参数值从集合中删除项目?

时间:2019-02-08 14:25:19

标签: c# collections

我正在尝试通过属性值删除该项目。 删除方法有什么问题?

using System.Collections.Generic;

namespace Autoworld
{
    class GoodCars
    {
        static List<Tech> cars = new List<Tech>();
        public class Tech
        {
            public string Name { get; set; }
            public double KM { get; set; }
        }

        static void Main()
        {
            cars.Add(new Tech()
            {
                Name = "Lada Vesta Sport",
                KM = 190
            });
            cars.Remove(new Tech()
            {
                Name = cars[0].Name
            });
        }
    }
}

0 个答案:

没有答案