(3)C#基本语法
C# 最新语法
https://docs.microsoft.com/zh-cn/dotnet/csharp/whats-new/csharp-10
C# 默认访问修饰符
https://www.cnblogs.com/lizhenlin/p/6773385.html
1、C#标识符
标识符是用来识别类、变量、函数或任何其它用户定义的项目。
在 C# 中,类的命名必须遵循如下基本规则:
标识符必须以字母开头,后面可以跟一系列的字母、数字、下划线。标识符中的第一个字符不能是数字。
标识符不能是 C# 关键字。
2、标识符的命名规则
标识符一般有两种命名规则
.每个单词开头的字母大写(如 TestCounter)
.除了第一个单词外的其他单词的开头字母大写. 如. testCounter
3、C#关键字
关键字是 C# 编译器预定义的保留字。这些关键字不能用作标识符,但是,如果您想使用这些关键字作为标识符,可以在关键字前面加上 @ 字符作为前缀
保留关键字 | ||||||
abstract | as | base | bool | break | byte | case |
catch | char | checked | class | const | continue | decimal |
default | delegate | do | double | else | enum | event |
explicit | extern | false | finally | fixed | float | for |
foreach | goto | if | implicit | in | in (generic modifier) |
int |
interface | internal | is | lock | long | namespace | new |
null | object | operator | out | out (generic modifier) |
override | params |
private | protected | public | readonly | ref | return | sbyte |
sealed | short | sizeof | stackalloc | static | string | struct |
switch | this | throw | true | try | typeof | uint |
ulong | unchecked | unsafe | ushort | using | virtual | void |
volatile | while | |||||
上下文关键字 | ||||||
add | alias | ascending | descending | dynamic | from | get |
global | group | into | join | let | orderby | partial (type) |
partial (method) |
remove | select | set |
4、C#注释
C#的注释有三种方法
// 单行注释
/* */ 多行注释
/// 在类或方法前面,连续输入3个“/”,用于对类和方法进行注释可以折叠一段代码可以用。
5、C#代码区分大小写
6、折叠功能
#region到#endregion之间的代码具有折叠功能
#region //折叠代码 //折叠代码 //折叠代码 //折叠代码 #endregion
7、字面值
例如
int a=3;
3就是字面值
string b="snowsea";
snowsea就是字面值
8、一条语句要用 ; 结束
9、基本结构
using System; name ConsoleApplicaionl
{ class Program
{ static void Main(String[] args)
{ ... } } }
三目运算
a=3>4?3:4;