Can structs contain fields of reference types

前端 未结 6 2088
一生所求
一生所求 2020-11-30 00:30

Can structs contain fields of reference types? And if they can is this a bad practice?

6条回答
  •  死守一世寂寞
    2020-11-30 01:05

    Sure thing and it's not bad practice to do so.

    struct Example {
      public readonly string Field1;
    }
    

    The readonly is not necessary but it is good practice to make struct's immutable.

提交回复
热议问题