例子:
class document
{
public void new()
{
}
public void save()
{
}
}
visual studio 声称新的是带有错误的红色下划线。 我需要全部小写以安排清洁
For those seen this Questions:* **(Answer)C# Naming rule violation: Words must be begin with Upper Cases!!!
最佳答案
不,你不能,因为 new
是一个关键字。但是,是的,如果被接受,您可以通过 @
转义关键字。
class document
{
public void test()
{
this.@new();
}
public void @new()
{
Console.WriteLine();
}
}
C#建议在类名和方法名中使用大驼峰式。
由于关键字是小写字母,因此大写驼峰名称(如 void New()
)不受影响。
关于C# 是否可以在名为 new 的类中命名一个方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38044982/