Why does a static constructor not have any parameters?

前端 未结 9 1545
忘掉有多难
忘掉有多难 2021-02-07 03:02

Per MSDN:

A static constructor does not take access modifiers or have parameters.

A static constructor is called automatically to ini

9条回答
  •  难免孤独
    2021-02-07 03:32

    Make an empty constructor to the static class, and put the parametrized code to a normal function. If you call this function, the static class will be created.

    the static class:

    static class DataB
    {
        static DataB(){}
    
        public static void funcWithParams(string st)
        {...}
    }
    

    you can create it like this:

    DataB.funcWithParams("some string");
    

提交回复
热议问题