本文介绍了错误 1 只有赋值、调用、递增、递减、等待和新对象表达式可以用作语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public partial class frmManager : Form
{
public String Name
{
get
{
txtName.Text;
}
set;
}
}
错误 1 只有赋值、调用、递增、递减、等待和新对象表达式可以作为语句使用
Error 1 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
推荐答案
如果要使用 getter 和 setter 并定义自定义 getter,则还需要定义自定义 setter.例如:
If you want to use the getter and setter and define a custom getter you also need to define a custom setter. For eg :
public String Name
{
get { return txtName.Text; }
set { txtName.Text = value; }
}
或者你可以创建getonly"属性:
Or you can create "getonly" properties :
public String Name
{
get { return txtName.Text; }
}
这篇关于错误 1 只有赋值、调用、递增、递减、等待和新对象表达式可以用作语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!