C# 从另一个表单在字典中添加项
我正试图使用另一种形式的词典,但我不能 表格1.csC# 从另一个表单在字典中添加项,c#,dictionary,C#,Dictionary,我正试图使用另一种形式的词典,但我不能 表格1.cs public partial class Form1 : Form { public DataNode rootNode; public static Dictionary<string, string> documents = new Dictionary<string, string>(); public Form1() { } 错误:
public partial class Form1 : Form
{
public DataNode rootNode;
public static Dictionary<string, string> documents = new Dictionary<string, string>();
public Form1() {
}
错误:无法使用实例引用访问;改为使用类型名称限定它
我如何才能完成此访问?能够以任何形式访问和使用词典…词典是静态的,因此您可以只使用类型名称:
Form1.documents.Add(pageGuid, addcapitulo.blankRtfText);
字典是静态的,因此您可以只使用类型名称:
Form1.documents.Add(pageGuid, addcapitulo.blankRtfText);
要访问静态类型,您需要:
Form1.documents
如错误所示,您无法使用Form1
的实例进行访问
我建议将字典设置为非静态的
:
public Dictionary<string, string> documents = new Dictionary<string, string>();
公共字典文档=新字典();
那么您当前的代码将按原样工作。我找不到定义字典的理由来访问您需要的静态类型:
Form1.documents
如错误所示,您无法使用Form1
的实例进行访问
我建议将字典设置为非静态的
:
public Dictionary<string, string> documents = new Dictionary<string, string>();
公共字典文档=新字典();
那么您当前的代码将按原样工作。我找不到定义字典的理由static