"I want to display the list Categoty and its items count"
Here i have both the List and the Dictionary
public static List<Category> categories = new List<Category>();
public static Dictionary<string, ProductInfo> ProductInformation = new Dictionary<string, ProductInfo>();
Here are the AddProduct method
static Dictionary<string, ProductInfo> ProductDictionary { get; } = new Dictionary<string, ProductInfo>();
static void AddProduct(ProductInfo product)
{
var productExist = ProductDictionary.Any();
if (!productExist)
{
// Add product to list
}
else
{
// Throw an ArgumentException
}
}
Problem : i want to display the categories made and the count of its products using this code:
static void ShowCategory()
{
foreach (var c in Category.categories)
Console.WriteLine(ProductDictionary[c.Name].Count);
Console.ReadKey(true);
ConsoleKey key = ConsoleKey.Escape;
}
I get an error that says:
CS1503: cannot convert from 'method group' to 'bool'
What does that mean?
CodePudding user response:
I get an error that says:
CS1503: cannot convert from 'method group' to 'bool'
What does that mean?
I means exactly what it says. In your case Count
is a method and not a property as you expect it to be. Change your code to:
Console.WriteLine(ProductDictionary[c.Name].Count());