Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Display list and its items, also display items counts

"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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading