在扩展类时,我发现在访问基类中的方法时使用base(在 VB 中)关键字非常具有描述性。MyBase在访问扩展基类的类中的函数时使用this(在 VB 中) 关键字。Me这也适用于没有继承的“平面”结构。
我觉得读这个更容易:
public class World
{
public String baseName = "World";
}
public class Hello : World
{
public String thisName = "Hello";
public String GetNames()
{
return this.thisName + " " + base.baseName;
}
}
比这个:
...
public String GetNames()
{
return thisName + " " + baseName;
}
...
现在,我的问题是:是否可以在 Visual Studio/C# 的编译时强制使用thisand base,以便如果您在代码中不使用这些关键字,编译器会抛出错误或警告?