Member '' cannot be accessed with an instance reference

前端 未结 10 1923
我在风中等你
我在风中等你 2020-11-22 10:39

I am getting into C# and I am having this issue:

namespace MyDataLayer
{
    namespace Section1
    {
        public class MyClass
        {
            publ         


        
10条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 11:17

    YourClassName.YourStaticFieldName
    

    For your static field would look like:

    public class StaticExample 
    {
       public static double Pi = 3.14;
    }
    

    From another class, you can access the staic field as follows:

        class Program
        {
         static void Main(string[] args)
         {
             double radius = 6;
             double areaOfCircle = 0;
    
             areaOfCircle = StaticExample.Pi * radius * radius;
             Console.WriteLine("Area = "+areaOfCircle);
    
             Console.ReadKey();
         }
      }
    

提交回复
热议问题