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 153 views
1 answer 198 views
1 answer 198 views
1 answer 179 views
1 answer 184 views
1 answer 168 views
168 views asked Dec 31, 2016 by avibootz
1 answer 139 views
...