Static code blocks

前端 未结 5 2117
遇见更好的自我
遇见更好的自我 2021-02-06 19:56

Going from Java to C# I have the following question: In java I could do the following:

public class Application {
    static int attrib         


        
5条回答
  •  我在风中等你
    2021-02-06 20:43

    In your particular scenario, you could do the following:

    public class Application { 
        static int attribute = 5;
       // ... rest of code 
    }
    

    UPDATE:

    It sounds like you want to call a static method. You can do that as follows:

    public static class Application {
        static int attribute = 5;
    
        public static int UtilityMethod(int x) {
            return x + attribute;
        }
    }
    

提交回复
热议问题