Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protection level error in dictionary [closed]

Tags:

c#

dictionary

I'm getting this error message "Inaccessible due to its protection level" in the last line but I've checked and everything seems to be public. What could be wrong?

using System;
using System.Collections.Generic;

namespace Test
{
    class Sneakers
    {

        public string _brand;
        public Sneakers(string brand)
        {
            _brand = brand;
        }
        public string Show()
        {
            return "The brand is: " + _brand;
        }
        public static string Show(Sneakers mySneak)
        {
            return mySneak.Show();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {

            Sneakers mySneak = new Sneakers("Nike");

            Dictionary<Sneakers, double> collection = new Dictionary<Sneakers, double>();
            collection.Add(mySneak, 10);

            foreach (KeyValuePair<Sneakers, double> item in collection)
            {
                Console.WriteLine(Sneakers.Show(item.key));//HERE IS THE ERROR IN "key"
            }
        }
    }
}
like image 899
user3646717 Avatar asked May 04 '16 04:05

user3646717


1 Answers

use Key not key

Console.WriteLine(Sneakers.Show(item.Key));
like image 73
Artem Avatar answered Sep 28 '22 06:09

Artem