Reputation:
In my apps i need a List to pass as a parameter.
i write it
List<stuff.Inventory> inv = new List<stuff.Inventory>();
inv.Add(stuff.Inventory.NotAvailable);
inv.Add(stuff.Inventory.None);
inv.Add(stuff.Inventory.Coming);
if (stuff.isStuffinInv(inv, prodID))
{
// ...
}
are my way is right or need any new way to do this
Upvotes: 2
Views: 155
Reputation: 1500585
Well, aside from naming conventions and indentation, it looks okay.
With C# 3 you can use a collection initializer, like this:
List<Inventory> inventory = new List<Inventory>
{
Inventory.NotAvailable, Inventory.None, Inventory.Coming
};
if (stuff.isStuffInInv(inventory, prodID))
...
That's a generally more readable approach, IMO.
Upvotes: 6
Reputation: 5657
List<stuff.Inventory> inv = new List<stuff.Inventory>()
{
stuff.Inventory.NotAvailable,
stuff.Inventory.None,
stuff.Inventory.Coming
};
From what you've described though, would an enum be more suitable?
Upvotes: 2
Reputation: 13897
There's nothing particularly wrong with that code, but you might want to consider using LINQ to query your list, rather than having your isStuffInInv method.
if (inv.Any(x => x._?_ == prodID));
Upvotes: 0
Reputation: 82096
From the looks of it Inventory appears to be an emum. Have you considered using the FlagsAttribute instead?
Upvotes: 5