[A] Essential C # C # Overview

Starting today, learning "C # 7.0 Essence of" This book, by its very nature! Of course, had to find out about objects of thought and have some Java and C # programming foundation for, so no overall details of finishing in the learning process recorded for a simple first few chapters learning content ready to adopt QA and record the focus of refining the way recording, that is, for key and difficult and do not understand their own place before the adoption of discussion or question and answer form record.

C # cold knowledge

1, C # is case-sensitive language, incorrect case makes the code will not compile successfully .
2, C # Main method in addition to return void can return int, int status code, return 0 means error .
3, line or not does not affect the separate statement, C # statements separated by semicolons identified only as long as there is a semicolon-line display the results on the exchange, not been displayed in a row.
4, C # allows multiple assignment in the same statement, and declare that a plurality of the same type may also be separated by commas , for example:

       private static void Main()
        {
            string tml2, tml3;
            var tml1 = tml2 = tml3 = "多个tml都能接受值";
            System.Console.WriteLine(tml2);
            System.Console.WriteLine(tml1);
            System.Console.WriteLine(tml3);
        }

5, the immutability of the string, the string is not allowed to know that change, can not modify the data cited initially, only to re-assignment to point to the new location in memory .
6, Java requires the file name and class name must be consistent, in a C # file can contain multiple class and category code through partial class split into multiple files
7. What is the SDK? In fact, and in Java JDK similar, including: compiler, runtime execution engine (CLR), "run-time" language access can access framework as well as other tools might and SDK bundled , it means a development environment.

New knowledge of C #

1, string interpolation function , my mother no longer worried about the use of composite formatting error occurred

    private static void Main()
     {
        const string tml2 = "多个tml都能接受值";
        const string tml3 = "我都能接受";
        System.Console.WriteLine($"字符串插值{tml2}{tml3}"); //字符串插值多个tml都能接受值我都能接受
     }

Previously formatted composite index by the way, the order of output variables, not intuitive.

2, before the string is not processed using @ conform to indicate an escape sequence, and literally explain all the whitespace characters , popular to say, before want to output newline, takes place in need wrap plus \ n, now just as they wrap on the line. And $ @ and can be used in combination, can achieve the effect of a new line:

     private static void Main()
        {
            const string tml2 = "多个tml都能接受值";
            const string tml3 = "我都能接受";
            System.Console.WriteLine($@"字符串插值
            {tml2}{tml3}");
            //字符串插值
            //多个tml都能接受值我都能接受
        }

Identifier specification

1, an identifier naming convention (individual)

Combined with standard specifications and their habits, summed up such identifiers Use: combined under C # naming conventions:

  • Identifiers can contain uppercase and lowercase letters, numbers, underscores and @ characters .
  • Identifiers can not begin with a number and can not contain spaces.
  • The identifier must be case-sensitive . Uppercase and lowercase letters are considered different letters.
  • @ Character is only the first character identifier. An identifier with an @ prefix is ​​called a verbatim identifier.
  • You can not use C # keywords. However, the @ character add keywords can be a legal identifier, it is not recommended.
  • Not the same as the library name to C #.

Do not use abbreviations of words , pay attention to its clear and not short of; try not to use the underscore, it is best to use only non-abbreviated form of numbers and letters .

2, the identifier written specification (individual)

First clear two naming specification:

  • Camel (hump) nomenclature : the first letter of the first word lowercase, uppercase first letter of subsequent words: for variable names (parameter name, member variables, local variables), such as: tmlGetGirl
  • Pascal (Pascal) nomenclature : the first letter of each word are capitalized: suitable for methods and classes , such as: TmlAiTest

Recommend the use of a name or noun phrase naming classes, it is recommended to use the first word as a verb phrases to name methods .

Published 240 original articles · won praise 114 · views 180 000 +

Guess you like

Origin blog.csdn.net/sinat_33087001/article/details/103156934