编辑器:VS
.NET:平台
ASP.NET:是一个网站开发的技术,基于.NET平台
.NET FrameWork:运行框架,适用.net开发的程序、只适用win平台
Mono:一个第三方的 .NET Framework 实现
.NET Core:开源运行框架,支持多平台
.NET5、.NET6 :.NET Core重命名、对.NETCore升级优化(最新方向)
C#注释符:/// // /* */
Nuget:包管理开发工具、可分享获取package
MVC:整站框架
WebAPI:没有View,专注后端
常用变量:
整形:byte、int、long
浮点型:float、double
字符:char
字符串:string
布尔:bool
数据类型:
值类型:整形 、浮点型、字符、结构体、枚举
引用类型:类、字符串
类型转换:
1、(int)变量 :int b = (int)a;
2、int.Parse(变量) :int str1 = int.Parse(str);
3、int.TryParse(变量 s, out int result) :
string str = "100"; int i; bool strbool = int.TryParse(str, out i);
4、Convert.ToInt32(变量):
string str = "100";
int strInt= Convert.ToInt32(str);
运算符:
算术运算符:+ - * / % ++ --
关系运算符:== != > < >= <=
逻辑运算符: && || !
位运算符:&、 | 、^、<< 、>>
判断:
if else :
Switch:
switch(expression){
case constant-expression :
statement(s);
break;
case constant-expression :
statement(s);
break;
/* 您可以有任意数量的 case 语句 */
default : /* 可选的 */
statement(s);
break;
}
循环:
while:
for:
for (int a = 10; a < 20; a = a + 1)
{
Console.WriteLine("a 的值: {0}", a);
}
foreach:
foreach (int element in fibarray)
{
System.Console.WriteLine(element);
}
do while :
break:跳出循环
continue :直接下一次循环
枚举:
using System;
public class EnumTest
{
enum Day { Sun, Mon, Tue, Wed, Thu, Fri, Sat };
static void Main()
{
int x = (int)Day.Sun;
int y = (int)Day.Fri;
Console.WriteLine("Sun = {0}", x);
Console.WriteLine("Fri = {0}", y);
}
}
当上面的代码被编译和执行时,它会产生下列结果:
Sun = 0
Fri = 5
结构体:
using System;
using System.Text;
struct Books
{
public string title;
public string author;
public string subject;
public int book_id;
};
public class testStructure
{
public static void Main(string[] args)
{
Books Book1; /* 声明 Book1,类型为 Books */
Books Book2; /* 声明 Book2,类型为 Books */
/* book 1 详述 */
Book1.title = "C Programming";
Book1.author = "Nuha Ali";
Book1.subject = "C Programming Tutorial";
Book1.book_id = 6495407;
Console.WriteLine( "Book 1 title : {0}", Book1.title);
Console.WriteLine("Book 1 author : {0}", Book1.author);
Console.WriteLine("Book 1 subject : {0}", Book1.subject);
Console.WriteLine("Book 1 book_id :{0}", Book1.book_id);
}
}
String 类:
格式化:
string.Format("{0:y yy yyy yyyy}",dt); //17 17 2017 2017
关键字:
命名空间:namespace
引入:using
static :
readonly:运行时常量,程序运行时进行赋值操作,赋值完成后不能在更改
const:编译时必须赋值
类:class
类修饰符:
private :禁止外部访问
public: 公开
protected :允许子类访问
可空类型:
int? i = 3;
异常捕获:
try
{
// 引起异常的语句
}
catch( Exception ex )
{
throw
}
finally
{
// 要执行的语句
}
数组:
double[] balance = { 2340.0, 4523.69, 3421.0};
int [] marks = new int[5] { 99, 98, 92, 97, 95};
double[] balance = new double[10];
int [] marks = new int[] { 99, 98, 92, 97, 95};
Array类对数组进行操作
二维数组:
int[,] a = new int[5, 2] {{0,0}, {1,2}, {2,4}, {3,6}, {4,8} };
多维数组:
int[, ,] muarr = new int[2, 2, 3]
{
{{1,2,3},{4,5,6}},
{{7,8,9},{2,3,4}}
};
转义字符:
\' 单引号
\" 双引号
\\ 反斜杠
\0 空字符
\a 警报符
\b 退格
\f 换页
\n 换行
\r 回车
\t 水平制表
\v 垂直制表
占位符:
string m=String.Format(“{0}”,c); //字符串格式输出
方法:
静态类:
static xx XXXX(){}
使用类名.方法名访问
一般类:
void XXX(){}
new 类生成对象访问
Out和ref:
传入参数时使用,对象是值类型参数,是本体地址传入,会对原数值造成影响
如果参数不使用关键字,则是复制一份进入,不会对原数值造成影响
区别:
Out:必须在方法中对其完成初始化,适用于返回多个数据
ref: 传入必须初始化
断点调试:
打断点,运行,逐语句,逐过程
构造函数:
完成对类成员的初始化
无参构造、有参构造