您的位置:首页 > 其它

if---(switch-case)语句初步学习总结

2014-03-10 19:06 363 查看
Daily sentence: Happiness is about having each tiny wish come true. 幸福就是达成每一个Tiny Wish.

Ctrl+E D C#自动排版.

强制转换:

如果表达式中含有一个double类型的的操作数时候,整个表达式都提升为double类型.

int a=(int)3.14; 将3.14强制转换为int类型.并将值赋给a.

int 变量Convert.ToInt32(Console.ReadLine(输入的字符串)); 将输入的字符串转换为int类型.

Convert转换不再仅是内存级别的转换,而是考虑数据意义的转换.Convert是一个加工转换的过程.
(要明白为什么转换?!)
Convert.ToInt32();
Convert.ToString(); (一切类型都可以转换成string类型)

int a = 10;
Console.WriteLine(a.ToString()); 将int转换为string类型.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace switch_case
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个字母(A-E)?");
string input = Console.ReadLine();
int salary = 5000;
bool sign = false;
switch(input)
{
case "A":
salary += 500;
break;
case"B":
salary += 200;
break;
case"C":
break;
case"D":
salary -= 200;
break;
case"E":
salary -= 500;
break;

default:
Console.WriteLine("你输入的英文字母有错误!");
sign = true;
break;

}
if (sign == false)
{
Console.WriteLine("你的工资是" + salary);
}

Console.ReadKey();

}
}
}


View Code

Long way to go......
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐