【发布时间】:2018-04-09 08:58:05
【问题描述】:
试图找出背后的原因。
场景#1
public class Customer
{
string _name = "Ram";
//now trying to assign some new value to _name on the next line
_name // this property is inaccessible on this line.
}
场景#2
public class BaseCustomer
{
protected string _name;
}
public class DerivedCustomer : BaseCustomer
{
_name //inaccessible here
public void SetName()
{
_name = "Shyam"; //accessible here
}
}
谁能告诉我这背后的原因是什么?
【问题讨论】:
-
我认为您标记的行是
_name = "Foo";是否正确?如果是这样,将其实际编辑到问题中会更加清晰。因为它是你有一个没有终止;的裸变量,这在任何上下文中都是无效的代码。 -
你如何推断它“不可访问”的结论?显示的 sn-ps 根本不是有效的 C# 语法。
-
@Fildor:每当我听到几乎所有开发人员都将某些东西称为“无法访问”时,这意味着“我在 IntelliSense 中找不到它”。跨度>
-
@Flater 是的 - 舒适的 IDE 的缺点......
标签: c# asp.net oop inheritance