How to define and use static constructor in static class with C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    static class Test
    {
        public static int n;

        static Test()
        {
            n = 100;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Test.n);
        }
    }
}


/*
run:
 
100

*/

 



answered Dec 31, 2016 by avibootz

Related questions

1 answer 248 views
1 answer 291 views
1 answer 290 views
1 answer 270 views
1 answer 285 views
1 answer 256 views
256 views asked Dec 31, 2016 by avibootz
1 answer 349 views
...