I want to let two classes communicate with each other. I want to use a dictionary to be able to add items. I’ve simplified my pattern to solve it easily. How to use dictionary to add a new item.
I want to generate only one instance of MyClass. That is important. This is a kind of a trick…
public interface IHost
{
}
public class MyClass:IHost
{
public Dictionary<int,string>; dic { get; set;}
public MyClass()
{
dic = new Dictionary<int,string>();
}
}
public class MyClass2 : IHost
{
public MyClass()
{
}
public void Save()
{
dic.Add(1,"vxcvcx");
}
}
Error that I get:
The name ‘dic’ does not exist in the current context
use a base class instead of an interface: