定义获取或C#设置 [英] define get or set in c#
问题描述
喜 朋友我有问题,使用GET或C#设置类 当我使用获取或设置提示错误(无效令牌{类) 请,请参见下面code,我在它这个问题
静态INT ABCD
{
得到
{
返回_abcd;
}
}
感谢名单
这是完整的code,我没有这个问题,你的任何codeS,但只是这样的:
命名空间ConsoleApplication2
{
类节目
{
类车
{
私人诠释_SPEED;
公众诠释速度;
{
得到
{
返回_SPEED
}
}
}
}
}
您已经张贴的片断是好的,因为它是,也是在关于此错误,因为它有的正确数量{
到}
并以正确的顺序。
看,你已经把它(可能是外面的一类),或寻找额外的}
的文件中。
更新:(以下编辑有问题)
您的问题就在这里:
公众诠释速度; //< - ;不应该在这里
和
返回_SPEED //< - 失踪的;
的属性应该是这样实现:
公众诠释速度
{
得到
{
返回_SPEED;
}
}
hi friends i have problem with using get or set in class in c# when i use get or set in gives error(invalid token { in class) pls, see below code,i have this problem in it
static int abcd
{
get
{
return _abcd;
}
}
thanx
this is the complete code,i dont have this problem with any of your codes but just this:
namespace ConsoleApplication2
{
class Program
{
class Car
{
private int _speed;
public int Speed;
{
get
{
return _speed
}
}
}
}
}
The snippet you have posted is fine as it is, also in regards to the error, as it has the correct number of {
to }
and in the right order.
Look at where you have placed it (possibly outside of a class), or look for extra }
in the file.
Update: (following edit in question)
Your issue is here:
public int Speed; // <-- ; should not be here
And:
return _speed // <-- missing the ;
The property should be implemented like this:
public int Speed
{
get
{
return _speed;
}
}
这篇关于定义获取或C#设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!