Initialization Order of Static Fields in Static Class

前端 未结 3 1031
庸人自扰
庸人自扰 2020-11-27 05:29

given the following code:

public static class Helpers
{
   private static Char[] myChars = new Char[] {\'a\', \'b\'};

   private static Int32 myCharsSize =          


        
3条回答
  •  不知归路
    2020-11-27 05:55

    At first glance, I wouldn't be sure, and I had to try this out to see if it even compiled.

    Given that, I would initialize the value in a static constructor.

提交回复
热议问题