Skip to main content
 首页 » 编程设计

c#之我应该使用属性来访问基类全局变量吗

2024年02月13日11xxx_UU

我有这样一个类结构:

public class PingtreeReq : ProviderRequest 
{ 
    // I want to use _residentialService here! 
} 
 
public class ProviderRequest 
{ 
    // Should this be a variable or property? 
    protected Dictionary<int, string> _residentialSerice; 
} 

如果我想使用来自 MyLenderRequest 的这个变量,使用属性更合适还是像这样访问它作为 protected 变量是否合适?

请您参考如下方法:

_residentialStatus 更像是一个私有(private)变量,是类私有(private)的。您可以在封装私有(private)变量的 ProviderRequest 中添加一个 protected 属性,并在 ProviderRequest 中使用它。