Method Calling Public/Private Members or Methods Best Practice - C#.NET

后端 未结 2 1874
难免孤独
难免孤独 2021-01-18 12:26

What is the best practice for calling members/fields from a private method and public method? Should the private method always call private fields or should they call the pu

2条回答
  •  余生分开走
    2021-01-18 13:07

    In some cases your public property might contain some logic which you need and in that case you will always use the property instead of the local variable, if you are sure that you want to use the private member variable, and not expose that functionality to the outside world, make that particular method private.

提交回复
热议问题