- Home /
 
 
               Question by 
               YesKlam · Dec 28, 2012 at 11:23 AM · 
                c#inventoryinventory system  
              
 
              [C#] Grouping variables
I'm trying to write an inventory system, for the weight I thought to create many groups of similar object and with a foreach, assign a weight for any object in that group. So I've tried to do this with an array, but this isn't so much useful. How can I do?
               Comment
              
 
               
              Answer by whydoidoit · Dec 28, 2012 at 11:55 AM
You should can use Linq:
   using System.Linq;
   ...
   foreach(var group in yourItems.GroupBy(i=>i.somethingThatRepresentsType))
   {
        //Here group.Key is the value of somethingThatRepresentsType
        foreach(var item in group)
        {
              item.weight = someValueYouLookupOfKey;
        }
   }
 
              Your answer
 
             Follow this Question
Related Questions
How do I make my item only open if there is room in my Inventory? 3 Answers
Clone a component, add it to a list and destroy the GameObject 1 Answer
chest items get added to inventory 2 Answers
Searching your inventory for an item,How do i search for an item in my inventory? 1 Answer
Issues with Inventory script 0 Answers