[英]does not contain a definition defination
在我声明之后,这就是我得到的错误
protected void Page_Load(object sender, EventArgs e)
{
List<String> LabelTextList = new List<String>();
dr = cmd.ExecuteReader();
while (dr.Read())
{
LabelTextList.add(dr[0].ToString());
}
}
错误1'MasterPage_Profile'不包含'LabelTextList'的定义,并且找不到扩展方法'LabelTextList'接受类型为'MasterPage_Profile'的第一个参数(您是否缺少using指令或程序集引用?)
[更新]现在它说:
'System.Collections.Generic.List'不包含'add'的定义,找不到扩展方法'add'接受类型为'System.Collections.Generic.List'的第一个参数(是否缺少using指令或装配参考?)
删除this
LabelTextList
是局部变量。
protected void Page_Load(object sender, EventArgs e)
{
List<String> LabelTextList = new List<String>();
dr = cmd.ExecuteReader();
while (dr.Read())
{
LabelTextList.add(dr[0].ToString());
}
}
要解决此问题,请将其更改为以下内容
LabelTextList.Add(dr[0].ToString());
LabelTextList
值是一个局部变量定义。 当给表达式加上前缀时this.
它告诉编译器寻找值的成员,而不是本地的。
这是一个与名为LabelTextList
的字段一起使用的反示例this.
List<String> LabelTextList = new List<String>();
protected void Page_Load(object sender, EventArgs e)
{
dr = cmd.ExecuteReader();
while (dr.Read())
{
this.LabelTextList.Add(dr[0].ToString());
}
}
同样,如果将值保留为本地值,则标准命名模式将是labelTextList
而不是LabelTextList
。 这不是语言所必需的,而是首选样式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.