码迷,mamicode.com
首页 > Windows程序 > 详细

C#笔记第二周

时间:2015-02-03 18:58:13      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

 1 namespace ConsoleApplication1
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             string name = "卡卡西";
 8             string address="火影村";
 9                 string mail="kakaxi@qq.com";
10                 decimal wage = 3000m;
11             Console.WriteLine("我叫"+name+",我来自"+address+",我的邮箱是"+mail+",我每个月的工资是"+wage+"");
12             Console.ReadKey();
13 
14 
15 
16         }
17     }
18 }

 decimal  如果希望实数被视为 decimal 类型,请使用后缀 m 或 M。如果后面没有加M,当输入带有小数点的数字的时候,它会被误认为double类型的,而double可带小数点。

decimal 用于关于财政金融方面的数字!

 1 namespace ConsoleApplication1
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             string name = "卡卡西";
 8             string address="火影村";
 9                 string mail="kakaxi@qq.com";
10                 decimal wage = 3000m;
11             Console.WriteLine("我叫{0},我来自{1},我的邮箱是{2},我每个月工资是{3}。",name,address,mail,wage);
12             Console.ReadKey();
13 
14 
15 
16         }
17     }
18 }

 交换变量的两种方法

 1 namespace ConsoleApplication1
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7 
 8             int a = 80;
 9             int b = 10;
10 
11             a = a - b;
12             b = b + a;
13             a = b - a;
14             Console.WriteLine("交换后,a={0},b={1}", a, b);
15             Console.ReadKey();
16 
17 
18         }
19     }
20 }
 1 namespace ConsoleApplication2
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             int n1 = 10;
 8             int n2 = 20;
 9             int temp = n1;//建立一个第三方变量,使它等于n1;
10 
11             n1 = n2;//将n2赋值给n1;
12             n2 = temp;//第三方等于n1的值重新赋值给n2;
13             Console.WriteLine("n1={0},n2={1}.",n1,n2);
14             Console.ReadKey();
15             
16 
17         }
18     }
19 }

 

用户信息的输入 readline的用法,兼有暂停当前画面的功能

 1 namespace ConsoleApplication3
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             Console.WriteLine("你今年多少岁啦?");
 8             string age = Console.ReadLine();
 9 
10 
11             Console.WriteLine("恭喜你,你今年已经{0}岁啦!", age);
12             Console.ReadKey();
13         }
14     }
15 }

 

C#笔记第二周

标签:

原文地址:http://www.cnblogs.com/flying-coder/p/4268642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!