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"
}
}
}
}
use Key not key
Console.WriteLine(Sneakers.Show(item.Key));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With