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

本文介绍了一个简单的C#程序实例,包括变量声明、写入控制台和使用格式化字符串。通过这个示例,读者可以了解C#语言的基本语法和控制台输出操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        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).
        }

 

转载于:https://www.cnblogs.com/limeina/p/3520789.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值