4
A
回答
6
3
不幸的是,C#不支持const方法或const参数。 C#2.0中有一项新功能在类似场景中有所帮助。使用C#2.0 get和set属性访问器可以具有不同的可访问性。这样就可以使get访问公共和保护作为设定如下
class MyClass
{
int _val;
public int Val
{
protected set { _val = value; }
get { return _val; }
}
}
+0
谢谢[Fyre(HTTP://计算器.com/users/1314262/fyre),这很有帮助 – zeropoint 2012-07-26 07:20:51
+1
或者在C#3中...'public int Val {get;保护组; }' – 2012-07-26 07:32:09
相关问题
- 1. C++非const const引用函数重载
- 2. const和非const函数的重载是如何工作的?
- 3. 数组运算符[]重载const和非const版本
- 4. 为什么Boost.Range range_begin/end free函数为const和非const引用都重载?
- 5. 从非const对象调用const函数
- 6. 用const和non-const的回报重载函数引用
- 7. 函数重载为const char *,const char(&)[N]和std :: string
- 8. Const和非const访问解析为不同的重载?
- 9. 复制构造函数将const从const转换为非const?
- 10. 重建const函数
- 11. 返回一个const引用和非const成员函数调用
- 12. 为什么在一个类中需要const函数和非const?
- 13. const中的非const
- 14. 从const成员函数调用非const成员函数
- 15. 调用从const成员函数非const成员函数指针
- 16. 混乱上正在调用非const函数的const函数
- 17. 重载const而不是const函数的返回值语法
- 18. const如何使一个函数重载?
- 19. C++非const const的重载的方法选择
- 20. 比较const和非const指针?
- 21. 为什么有const和非const访问?
- 22. 成员函数的`const`和non-`const`版本是否有资格重载?
- 23. 麻烦与常量/非const重载
- 24. const const指针参数的非const指针参数
- 25. 避免重复const和非const版本的getters?
- 26. 重载的const和非const类方法返回C++中的引用
- 27. C++ - 使用操作符重载无法比较const和非const模板类型
- 28. 将const成员函数强制转换为非const
- 29. 调用一个const函数而不是它的非const版本
- 30. 私人非const和公共const成员函数 - 和平共存吗?
heyy你得到了'乔恩Skeet'答案:) – sunil 2012-07-26 06:49:33