C#学习系列之五:学写控制台小程序

跟着教程写了几个Console的小程序,一并记录下来。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 
 5 namespace ConsoleApplication1
 6 {
 7     class Program
 8     {
 9         /// <summary>
10         /// 程序入口点
11         /// </summary>
12         /// <param name="args">参数</param>
13         static void Main(string[] args)
14         {
15             //参数有两种 无和string[]数组
16             //返回值两种 void和int
17             Console.WriteLine("我最棒!");//WriteLin写一行,带换行
18             Console.Write("我真的最棒 ");//Write 不换行
19             Console.WriteLine("");
20             Console.WriteLine("-----------------");
21 
22             //int i = Console.Read();//Read 只返回ascii
23             //Console.WriteLine("i="+i);
24             //Console.WriteLine("-----------------");
25 
26             string str = Console.ReadLine();
27             Console.WriteLine("str="+str); // ReadLine可返回字符串
28             Console.WriteLine("str={0}",str); //占位符,从0开始。
29             Console.WriteLine("str={1}", str, "stc");
30             Console.WriteLine("str={0}+{1}", str, "stc");
31         }
32        
33     }
34 }
35 

 

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 
 5 namespace _02
 6 {
 7     class Program
 8     {
 9         static void Main(string[] args)
10         {
11            // double d = 1.1;
12             //float f = 1.1F;//字面量
13             Console.WriteLine("请输入第1个数字"); //WriteLine 返回值是string类型
14             double d1 = Convert.ToDouble( Console.ReadLine());//所以读取数据时必须要把string转换成double
15             Console.WriteLine("请输入第2个数字"); 
16             double d2 = Convert.ToDouble(Console.ReadLine());
17             Console.WriteLine("回车显示结果");
18             Console.WriteLine("{0}+{1}={2}",d1,d2,d1+d2);
19           
20         }
21     }
22 }
23 

 

posted @ 2009-10-04 00:50  Derekwong  阅读(379)  评论(0编辑  收藏  举报