I have a struct like this:
public struct stuff
{
public int ID;
public int quan;
}
and want to to remove the product where ID is 1.
I’m trying this currently:
prods.Remove(new stuff{ prodID = 1});
and it’s not working.
THANKS TO ALL
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using linq:
Maybe you even want to use
SingleOrDefault()and check if the element exists at all …EDIT:
Since
stuffis a struct,SingleOrDefault()will not return null. But it will return default( stuff ), which will have an ID of 0. When you don’t have an ID of 0 for your normal stuff-objects you can query for this ID: