标签:
第二天
初步了解C#语言基础
1.C#的输入输出
输出命令为:
Console.WriteLine();语句会自动换行
Console.Write();不会自动换行
1)数字输入可直接输入,也可以进行运算
Console.WriteLine(22); //22
Console.WriteLine(12+44); //56
2)文字输入必须用引号引起来
Console.WriteLine("abc");
Console.WriteLine("78"+"56");
输入命令:
string aaa = Console.ReadLine();
2.注释:// 注释一行
/*bulabulabula**/注释一段区域
/// 注解函数
3.举例练习
1)统计下学员的基本信息
static void Main21(string[] args)
{
Console.WriteLine("*******信息调查表*********");//显示标题
Console.Write("姓名:");
string name =Console.ReadLine();
Console.Write("性别:");
string sex=Console.ReadLine();
Console.Write("毕业院校:");
string graduate =Console.ReadLine();
Console.Write("专业:");
string zhuanye=Console.ReadLine();
//显示
Console.WriteLine("*****刚才显示的内容********");
Console.WriteLine("姓名:"+name +" 性别:"+sex);
Console.WriteLine("毕业院校:"+graduate);
Console.WriteLine("专业:"+zhuanye);
}
2)设计一个简单地聊天问答软件
static void Main7548243(string[] args)
{
Console.WriteLine("小胖:你叫啥类?");
Console.Write("我:");
string name = Console.ReadLine();
Console.WriteLine("小胖:哦,原来你就是"+name+"啊,久仰大名。几岁啦?");
Console.Write("我:");
string age = Console.ReadLine();
Console.WriteLine("小胖:才"+age+"呀,比我小!!喜欢什么运动?");
Console.Write("我:");
string sport = Console.ReadLine();
Console.WriteLine("小胖:原来是" + sport + "啊,我喜欢篮球哎。");
}
4.注意事项
1)命令写完整,最后的分号要加上,文字要用英文双引号引起来
2)需要读取的命令,用双引号隔开,再用双加号连接起来
5.数据类型
1)基本类型
整型 int 只能放有限位数的整数-xxxx ~ xxxx,10位。
long
short
浮点 double 默认小数都是double
float 如果小数要作为float看待,需要在后面加上f,F的后缀‘
float a = 3.14f; float a = 3.14;//错
字符 char 用单引号,只能放一个字符。转义字符除外
char c = ‘A‘; char c = "A";//错 char c=‘ABC‘;//错
布尔 bool 只能放true,false。代码中只能是小写,而且不要加引号。
bool g = true; bool g = True;//错 bool g = "true";//错
2)引用类型
字符串 string 双引号,一个或多个字符组成。
string s = "abcdef"; string s = "a"; string s = ‘asdfasdf‘;//错
6.类型转换:
1.自动转换 - 只要不可能存在数据丢失的情况,都会自动转。
2.强制转换
对于数字:在被转换的值的左边加上小括号,在小括号中写上被转成哪种类型。
float a = (float)3.14;
对于字符串:字符串转成相对应的基本类型
法一:int a = int.Parse("字符串"); float b = float.Parse("字符串"); double c = double.Parse("字符串");bool d = bool.Parse("字符串")
法二:使用Convert
double d = Convert.ToDouble(s); float f = Convert.ToSingle(s);
int a = Convert.ToInt32(s);
7.小知识点
1)项目后缀
.config--配置文件
.csproj--项目文件
.sln--解决方案文件
.cs--源文件,即程序代码
2)快捷键
Ctrl+e,c,注释本行
Ctrl+e,u,取消注释
TAB,本行右移
shift+delete,删除一行
home,end,开头,结尾
标签:
原文地址:http://www.cnblogs.com/pangchunlei/p/5381089.html