Best way to expose protected fields

前端 未结 6 1092
不知归路
不知归路 2021-01-19 05:50

I have a base class like this:

 public class BaseModalCommand
 {

    protected object m_commandArgument;
    protected int m_commandID;
    protected int m_         


        
6条回答
  •  猫巷女王i
    2021-01-19 06:08

    Paul Alexander is correct and so is FxCop.

    You want to make your fields private and expose them through a property to prevent derived classes from changing the variable by themselves. Forcing them to go through a property gives the base class a chance to validate and/or reject any modifications.

提交回复
热议问题