输出与暂停
Consel.WriteLine("hello");
Consel.ReadKey();//暂停
快捷键
Ctrl+K+D——快速对齐代码
Ctrl+J——代码提示
Ctrl+L——删除行
Ctrl+Shift+Enter——换下行
Ctrl+Enter——换上行
Alt+↑——移动当前行,往上
Ctrl+Z——撤销
Ctrl+Y——恢复
Shift+Home——选中一行到头
Shift+End——选中一行到尾
Shift+↑——选中一行到上一行
F1——转到帮助文档
折叠代码:
#region 这些是冗余代码
代码
#endregion
注释
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ChuangzhiConsel
{
class Program
{
static void Main(string[] args)
{
}
/// <summary>
/// 取最大值
/// </summary>
/// <param name="n1">第一个参数</param>
/// <param name="n2">第二个参数</param>
/// <returns></returns>
public static int GetMax(int n1, int n2)
{
return n1 > n2 ? n1 : n2;
}
}
/// <summary>
/// 用来描述信息
/// </summary>
public class Person
{
public string name
{
get;
set;
}
public int age
{
get;
set;
}
}
}
类型
string 字符串””
char 字符”
decimal money=5000m;金钱类型一定要有m
double
float
int
变量使用规则
先声明、再赋值,最后使用。
String与string的区别
运行没区别,String是系统的,string是C#里的关键字,最后都映射到同一个。
像Python一样使用占位符:
安装挖坑的顺序输出。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ChuangzhiConsel
{
class Program
{
static void Main(string[] args)
{
String name1 = "张三";
String name2 = "李四";
Console.WriteLine("hello,{0} with {1}",name1,name2);
Console.ReadKey();
}
}
}
变量命名规则
保证变量名有实际意义,Camel,首单词首字母小写,区别的单词大写。字母开头、下划线、数字等组成,大小写敏感。HTML是不区分大小写的。变量名不允许重复的声明和定义。
类或方法命名
每个单词首字母大写,Pascal
不使用第三方变量交换
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ChuangzhiConsel
{
class Program
{
static void Main(string[] args)
{
int n1, n2;
n1 = 35;
n2 = 655;
n1 = n1 - n2;
n2 = n1 + n2;
n1 = n2 - n1;
Console.WriteLine("n1是{0},n2是{1}",n1,n2);
Console.ReadKey();
}
}
}
控制台程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ChuangzhiConsel
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("n1是:");
String str = Console.ReadLine();//接收控制台的输入
Console.WriteLine("n1是{0}", str);
Console.ReadKey();
}
}
}