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

1 Answer

0 votes
using System;

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

        public static int StaticProperty
        {
            get { return sp; }

            set { sp = value; }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int n = Test.StaticProperty;
            Console.WriteLine(n);

            Test.StaticProperty = 100;
            Console.WriteLine(Test.StaticProperty);
        }
    }
}


/*
run:
 
0
100

*/

 



answered Dec 31, 2016 by avibootz

Related questions

1 answer 204 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 198 views
...