Dinesh Kudale

Dinesh Kudale

  • 1.5k
  • 127
  • 16.9k

Why is static field inaccessible in another class?

Feb 18 2021 10:37 AM
  1. using System;  
  2.   
  3. namespace BagarRajuClassConsoleProj.ModuleClasses  
  4. {  
  5.     public class Greeks  
  6.     {  
  7.         private Greeks() //private constructor  
  8.         { }  
  9.         public static int count = 20;  
  10.   
  11.     }  
  12.     public class TestGreek  
  13.     {  
  14.         Greeks.count = 10; //gives error  
  15.     }  
  16. }  

 In the above code, the "count" field is inaccessible in TestGreek class.

It arises following an error message.

The name 'count' does not exist in the current context.

 
But as per my knowledge, the static fields can accessible in another class.

Answers (1)