explicit and implicit c#

前端 未结 7 2021
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 13:31

I\'m new to C# and learning new words. I find it difficult to understand what\'s the meaning of these two words when it comes to programming c#. I looked in the dictionary

7条回答
  •  借酒劲吻你
    2020-12-07 13:48

    Being explicit in C# is mainly about showing your intentions clearly and unambiguously.

    For example:

    class MyClass
    {
        string myField;
    
        void MyMethod(int someNumber)
        {
    
        }
    }
    

    In the above code the visibility of the class, field and method are all implied. They use the compiler defaults.

    Now, I can never remember what the compiler defaults are, and maybe your colleagues can't either, so rather than rely on everyone remembering what the defaults are, you can be explicit.

    public class MyClass
    {
        private string myField;
    
        public void MyMethod(int someNumber)
        {
        }
    }
    

提交回复
热议问题