ASP.NET 的问题,为什么这也提示错误

来源:百度知道 编辑:UC知道 时间:2024/06/18 16:49:37
protected void Button4_Click(object sender, EventArgs e)
{

ListBox2.Items.Clear; //清空listbox2里面的内容
//for (int i = 0; i < ListBox2.Items.Count;i++ ) {

// ListBox2.Items.RemoveAt[i];

//}
}
错误 1 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句 E:\xhj\application\firstWeb\Default.aspx.cs 52 9 E:\...\firstWeb\

ListBox2.Items.Clear;
改成这个
ListBox2.Items.Clear();

记到以后不小心属性加了括号也会出现这种错误,上面是方法不是属性

ListBox2.Items.Clear();

错误提示,翻译如下:
只有分配,调用,递增,递减和new对象表达式可用作语句
应该改成:ListBox2.Items.Clear();
clear是方法 //调用方法需用()结束