使用长词保留在C#中的变量名 [英] Use the long reserved word as a variable name in C#
问题描述
有点不寻常之一..但我不知道是否有人知道我怎么可以声明保留字作为一个变量。我有以下的代码,但它并不像我所用长变量名。我知道我可以重新命名它,但instrest缘故,我想知道,如果这是在所有可能的。
私人字符串纬度;
私人弦长;
公共字符串纬度
{
得到
{
返回纬度;
}
}
公共字符串长
{
得到
{
返回长;
}
}
是的,你可以,如果你的真正的希望:
私人字符串@long;
实际的名称的变量(如报告通过反射等)是刚长
;在 @
符号告诉编译器忽略的事实,这也是一个关键字。
我会非常强烈反对这一点,但是。
a bit of an unusual one.. but I was wondering if anyone knew how I could declare a reserved word as a variable. I have the following code, but it does not like my use of the long variable name. I know I could rename it, but for instrest sakes I would like to know if this is at all possible.
private string lat;
private string long;
public string Lat
{
get
{
return lat;
}
}
public string Long
{
get
{
return long;
}
}
Yes, you can if you really want to:
private string @long;
The actual name of the variable (as reported by reflection etc) is just long
; the @
sign tells the compiler to ignore the fact that it's also a keyword.
I would very strongly advise against this, however.
这篇关于使用长词保留在C#中的变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!