如何从用户列表中删除一个元素定义类? [英] how to remove an element from a list of user define class?

查看:109
本文介绍了如何从用户列表中删除一个元素定义类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的C#,请温柔给我,我已通过网为没有成功的几个小时搜索,我想从我的用户定义的类中删除元素。我该怎么做呢?

I am fairly new to c#, please be gentle to me, I have been searching through the net for a few hours without success, I want to remove an element from my user defined class. How do I do it?

下面是code的片段。

below is the snippet of the code.

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

 }

我想我需要实现某种IEnumerable的,但如何语法是什么样子?有人可以请给我一个工作片断?非常感谢

I think I need to implement IEnumerable of some sort, but how does the syntax look like? can someone please give me a working snippet? thanks a lot

推荐答案

这将消除与 价格= 300,所有级别2 对象体积= 400 从名单

This will remove all Level2 objects with Price = 300 and Volume = 400 from the list

ask.RemoveAll(a => a.price == 300 && a.volume == 400);

这篇关于如何从用户列表中删除一个元素定义类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆