1.有符号整数:sbyte,short,int,long
无符号整数:byte(8位),ushort,uint,ulong
2.浮点数:float(32位),double,decimal
3.其他:char(16位),bool,string.
1.隐式转换
如:short->int
2.显式转换
short a = (short)100;
Convert命令转换,用作将string转换为数值
如:Convert.ToDouble();
static int SumVals(params int[] vals){}
调用:SumVals(1,2,3,5);
通过关键字params可以接收任意个int参数
一般情况下都是值传递。
1.引用传递时使用关键字ref.
定义函数:
static void ShowDouble(ref int val){}
调用时也需要保持一致:
int num = 5;
ShowDouble(ref num);
注意:传入参数不能是常量(const int num),且必须已经初始化(不能假定初始化)。
2.关键字out
与ref类似,都可以将值传到外部,但out会认定传入参数是未赋值的,即使赋值了,也被清空。
foreach(string str in args){
}
struct Name{
public string a;
public void tostring(){}
}
delegate double Pross(double a,double b);
static double add(double a,double b){}
static double mul(double a,double b){}
//使用
Pross p = new Pross(add);
p(1,2);
通过委托可以自己决定调用哪个函数
using System.Diagnostics;
Debug.WriteLine();
Trace.WriteLine();//这发布了程序依然有信息打印