- Home /
Not a Unity3D question
Combine duplicates in a collection of class objects
Hi everyone. Essentially, I need to keep track of the stocks that I've sold each month. To do this, I tried to create a custom class-object to handle the properties of the stock. E.g. what code I've given it, what description it has, and the quantity of it bought by the customer. Here's the class below:
public class StockItem
{
public string Code;
public string Quantity;
public string Description;
public StockItem(string code, string qty, string desc)
{
Code = code;
Quantity = qty;
Description = desc;
}
}
I've managed to successfully create a report of each item that I've sold, with its quantity, description and code. However, I would like to know how much of each type of item I've sold over the month, using the code property.
In other words, I have a list of individual items (multiple duplicates) and I want to combine the duplicates into one stock, with the combined quantity. E.g. One customer buys two oranges, and the other buys three oranges. I would like this to just be logged as 5 oranges sold. How exactly would I go about doing this. Thanks.
I dont think this is a Unity3D question and as such goes against the moderation guidelines. Is there anyway you can turn it into one?
If not can I suggest just trying
Instead?
Sure thing. Thanks for the recommendation. It's just my questions never get answered on Stack Overflow.
Follow this Question
Related Questions
Frame Drop on a function dealing with an updated List type (Only once after new element Added) 0 Answers
null reference exception when I already checked if this was null 1 Answer
A node in a childnode? 1 Answer
Argument out of range when checking at List[0], C# 1 Answer
Card/Tile Game, loops dont update element0 of playerHand properly 1 Answer