我收到此错误消息"由于其保护级别无法访问"在最后一行,但我已检查,一切似乎是公开的.可能有什么不对?
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"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)