当前位置:首页 > Windows程序 > 正文

C#快速入门指南

C# 集成开发环境结构结构体枚举接口派生类全析

集成开发环境

Visual Studio

结构 using System;

包含 System 命名空间

class hello{ /*注释*/
static void Main(string\[\] args){
//一个文件一个main函数
}
}
结构体 struct Books{变量...}

结构不支持继承。
结构不能声明默认的构造函数

枚举 enum Day { Sun, Mon, tue, Wed, thu, Fri, Sat };

Day.Sun==0

Day.Mon==1

接口 public interface PaintCost {int getCost(int area);} 派生类 class Rectangle : hello, PaintCost{} 全析 namespace first{

命名空间声明

public class Test{

可以多个class
构造函数、析构函数、静态成员...

变量...

decimal a=10;

128 位精确的十进制值,28-29 有效位数

sbyte b=2;

8 位有符号整数类型

uint c;

32 位无符号整数类型

ulong d;

64 位无符号整数类型

ushort e;

16 位无符号整数类型

dynamic f=a,g=b;

存储任何类型的值在动态数据类型变量中

字符串

"hhh\"hhh\nhhh" == @"hhh"hhh\nhhh" == @"hhh"hhh hhh" "hhh" + "hhh"

字符串一堆方法:拆分,复制...

可空类型,即可以赋值为null

int? a,b=null; //a==null int a; //a==0

合并运算符

int b=a ?? 5; //a为null则b=5,否则b=a

多维数组

int [,] a = new int [3,4] { {0, 1, 2, 3} , /* 初始化索引号为 0 的行 */ {4, 5, 6, 7} , /* 初始化索引号为 1 的行 */ {8, 9, 10, 11} /* 初始化索引号为 2 的行 */ };

交错数组

int[][] scores = new int[5][]; for (int i = 0; i < scores.Length; i++) scores[i] = new int[4];

Array 类

scores.Rank; //获取数组的秩(维度) scores.Length; Array.Copy(Array, Array, Int32); /*从数组的第一个元素开始复制某个范围的元素 到另一个数组的第一个元素位置*/

其他运算符

&a //地址 *a //指针 obj is Car // 检查 obj 是否是 Car 类的一个对象。 obj as int //强制转换,即使转换失败也不会抛出异常。

常量

const

其他常量例如8进制数

0213

装箱与拆箱

object obj; obj = 100; //这是装箱 int a=obj as int; //这是拆箱

循环

foreach(变量 in 数组){}

方法...

public int plus(int a){return a+1;}

重载

public int plus(char a){return a+2;}

运算符重载

public static Box operator+ (Box b, Box c){...}

可重载

+, -, !, ~, ++, -- ( op-type operand )

+, -, *, \/, %,==, !=, <, >, <=, >= ( op-type operand, op-type2 operand2 )

不可直接重载

&&, ||

不可重载

+=, -=, *=, /=, %=,=, ., ?:, ->, new, is, sizeof, typeof

按值传递

(int a)

引用

(ref int a)

按输出传递,即变量最后一个值赋回去

(out int a)

传递数组给函数

(int[] a)

参数数组

int plus(params int[] arr)

传递时:

plus(512, 720, 250, 567, 889)

访问权限

温馨提示: 本文由杰米博客推荐,转载请保留链接: https://www.jmwww.net/file/10193.html