天天看点

Simple statements, blocks, Write, WriteLine and the format string.

static void  SimpleProgram()
        // A block is a sequence of zero or more statements enclosed by a matching set of curly braces; it acts as a single syntactic statement.
        {
            //A statement is a source code instruction describing a type or telling the program to perform an action.
            int var1 = 5;

            //Write is a menber of the Console class. It sends a text string to the program's console window.
            System.Console.Write("This is trival text.");

            //WriteLine is another member of Console, which performs the same functions as Write but appends a newline character to the end of each output string.
            System.Console.WriteLine("The value of var1 is {0}", var1); 

            //The first parameter must always be a string and is called the format string.
            //The format string can contain substitution markers
            //A substitution marker marks the position in the format string where a value should be substituted in the output string.
            //It consists of an integer enclosed in a set of matching curly braces. The integer is the numeric position of the substitution value to be used.
            //The parameters following the format string are called substitution values. These substitution values are numbered, starting at 0.
            System.Console.WriteLine("Two sample integers are {1}, {0} and {1}.", 3, 6);

            //A marker must not attempt to referrence a value at a position beyond the length of the list of substition values. 
            //If it does, it will not produce a compile error but a runtime error (called an exception).
        }