我是c#的新手,请对我温柔,我一直在网上搜索几个小时没有成功,我想从用户定义的类中删除一个元素.我该怎么做?
下面是代码的片段.
public class Level2
{
public double price { get; set; }
public long volume { get; set; }
public Level2(double price, long volume)
{
this.price = price;
this.volume = volume;
}
}
static void Main()
{
List<Level2> bid = new List<Level2>();
ask.Add(new Level2(200, 500));
ask.Add(new Level2(300, 400));
ask.Add(new Level2(300, 600));
// how to remove this element ???
ask.Remove(300, 400); //doesn't work
}
Run Code Online (Sandbox Code Playgroud)
我想我需要实现某种IEnumerable,但语法是怎样的?有人可以给我一个工作片段吗?非常感谢
这将从列表中删除所有Level2对象Price = 300 and Volume = 400
ask.RemoveAll(a => a.price == 300 && a.volume == 400);
Run Code Online (Sandbox Code Playgroud)