1.1 程序分析
[图片上传中...(image.png-58e3dc-1575532398542-0)]
1.2 计算机基本知识
home键:能把光标定位在一行代码的最前方。
end键:能把光标定位在一行代码的最后方。
pageup/pagedown:对当前文档进行翻页。
Ctrl+home/Ctrl+end:能把光标定位在代码的最前方/末尾。
1.3 标识符
总之:不能以数字开头,不能以@结尾,不能有.而且不能与关键字重复。
关键字都是小写的。
1.4 C#命名规范
Camel(驼峰)命名法
首个单词的首字母小写,其余单词的首字母大写(enemyHp)
Pascal(复活节)命名规范
每个单词的第一个字母都大写(EnemyHp)
如果使用到英文单词的缩写,全部使用大写(PI HP MP)
变量使用Camel命名,方法和类使用Pascal命名规范
1.5 块
块:以{开始,以}结束,方法的定义使用了块,块里面包含了语句。
类:以{开始,以}结束,
1.6 格式化字符串
对字符串进行格式化的输出,类似于print
Console.WriteLine("两个数相加{0}+{1}={2}",3,34,34);
1.7 变量声明
声明变量需要指定类型和变量名:
<type><name>;
type表示使用什么类型的盒子,来储存数据
name表示储存这个盒子的名字
实例:(每一个声明都时条语句,语句以;结束)
int age;
int hp;
string name;
int表示整数类型;
string表示字符串;
常见的变量类型:
一般使用float,在数字后面加f表示浮点数;如果是long类型,在后面加l
实例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _002_变量
{
class Program
{
static void Main(string[] args)
{
int age = 20;
int hp = 60;
string name = "siki";
Console.WriteLine(name);
byte myByte = 34;
int score = 6000;
long count = 100000000;
Console.WriteLine("myByte:{0};score:{1};count:{2}",myByte,score,count);
float myFloat = 12.5f;
double myDouble = 12.6;
Console.WriteLine("myFloat:{0};myDouble:{1}", myFloat, myDouble);
char myChar = 'a';
string myString ="a";
string myString2 = " ";
bool myBool = false;
Console.WriteLine("myChar:{0};mySring:{1};myString2:{2};myBool:{3}", myChar,myString
,myString2,myBool);
Console.ReadKey();
}
}
}
1.8 转义字符
如果希望名字里面带上双引号:
Console.WriteLine("主角名字是:\"{0}\"\n血量是:{1}\n等级是:{2}\n经验是:{3}\n",name,hp,level,exp);
需要在双引号前面加入两个转义符。
字符的Unicode值的作用略。
1.9 @
@能够使得字符串中的转义字符失效,如果需要"就打两个引号:
作用1:@能够使得字符串定义在多行
作用2:因为字符串中的\是\比较麻烦,使用@则只需要\。
所以@字符能够简化路径,更容易读懂。
2.0 注释的快捷键
ctrl+k+ctrl+c:注释代码。
ctrl+k+ctrl+u:取消注释代码。
2.1 多变量的声明与赋值
方法1:
int age2, name2, hp2;
age2 = 10;
name2 = 10;
hp2 = 10;
方法2:
int age = 10,name = "siki",hp = 34;
2.2 运算符
2.2.1 数字运算符:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 运算符
{
class Program
{
static void Main(string[] args)
{
int num1 = 10,num2 = 2;
int res1 = num1 + num2;
int res2 = num1 - num2;
int res3 = num1 * num2;
int res4 = num1 / num2;
int res5 = num1 % num2;
Console.WriteLine("res1:{0};res2:{1};res3:{2};res4:{3};res5:{4}", res1, res2, res3, res4, res5);
Console.ReadKey();
}
}
}
2.2.1 char运算符:
字符串和字符串,字符串和数字相加结果都是返回字符串。