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?
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
}
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
This will remove all Level2
objects with Price = 300 and Volume = 400
from the list
ask.RemoveAll(a => a.price == 300 && a.volume == 400);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With