When does it make sense to use a public field?

后端 未结 8 1221
北恋
北恋 2021-02-18 17:02

This is a question I have had for a while now:

When does it make sense to expose a field publicly like so?

public class SomeClass()
{
   public int backi         


        
8条回答
  •  独厮守ぢ
    2021-02-18 17:13

    When does it make sense to expose a field publicly?

    Among other places, on private classes as below.

    public class MyOuterClass
    {
          private class MyInnerClass
          {
                public int val ; // why bother w/boiler plate
          }
    }
    

提交回复
热议问题