c#中windows的基本控件:
1.Label:用于显示静态文本。
2.TextBox:用于文本的输入。
C#中的类型转换:
1.获得控件中的文本并将其转换Double类型: r = Convert.ToDouble(textBox1.Text);
2.将结果转换成文本并在控件中显示出来: textBox2.Text = Convert.ToString(c);
3.获得控件中的文本并将其转换float类型: a=Convert.ToSingle(textBox1.Text);
4.获得控件中的文本并将其转换int类型:n=Convert.ToInt32(textBox2.Text);
C#中的math库:
函 数 原 型 | 功 能 | 返 回 值 | 说 明 |
int Abs(int x) | 求整数x的绝对值 | 绝对值 |
|
double Acos(double x) | 计算arccos(x)的值 | 计算结果 | -1≤x≤1 |
double Asin(double x) | 计算arcsin(x)的值 | 计算结果 | -1≤x≤1 |
double Atan(double x) | 计算arctan(x)的值 | 计算结果 |
|
double atan2(double y, double x); | 计算arctan(y/x)的值 | 计算结果 |
|
long BigMul(int x, int y) | 计算x*y的值 | 计算结果 |
|
int Ceiling(double x) | 返回大于或等于所给数字表达式x的最小整数 | 最小整数 |
|
double Cos(double x) | 计算cos(x)的值 | 计算结果 | x的单位为弧度 |
double Cosh(double x) | 计算x的双曲余弦cosh(x)的值 | 计算结果 |
|
int DivRem(int x,int y,int z) | 计算x与y的商,并将余数作为输出参数进行传递 | x与y的商,z为余数 |
|
double Exp(double x) | 求ex的值 | 计算结果 |
|
int Floor (double x) | 返回小于或等于所给数字表达式x的最大整数 | 最大整数 |
|
int IEEERemainder(int x, int y) | 返回x/y的余数 | 计算结果 |
|
double Log(double x) | 计算ln(x)的值 | 计算结果 |
|
double Log10(double x) | 计算log10(x)的值 | 计算结果 |
|
double Max(double x, double y) | 返回x,y中的较大者 | 计算结果 |
|
double Min(double x, double y) | 返回x,y中的较小者 | 计算结果 |
|
double Pow(double x,double y) | 求xy的值 | 计算结果 |
|
int Round(double x) | 将x四舍五入到最接近的整数 | 计算结果 |
|
double Round(double x,int y) | 将x四舍五入到由y指定的小数位数 | 计算结果 |
|
int Sign(double x) | 返回表示x符号的值 | 数值x大于0,返回1;数值x等于0返回0;数值x小于0,返回-1 |
|
double Sin(double x) | 计算sin(x)的值 | 计算结果 | x的单位为弧度 |
double Sinh(double x) | 计算x的双曲正弦sinh(x)的值 | 计算结果 |
|
double Sqrt(double x) | 求的值 | 计算结果 | x≥0 |
double Tan(double x) | 计算tan(x)的值 | 计算结果 | x的单位为弧度 |
double Tanh(double x) | 计算x的双曲正切tanh(x)的值 | 计算结果 |
|
MessageBox的用法:
MessageBox.Show(文本,标题,按钮,图标)
参数说明:
1.文本:string类型,在消息框中显示文本;
2.标题:string类型,要在消息框标题栏中显示文本
3.按钮:该参数为MessageBoxButtons枚举类型之一。
4.图标:该参数为MessageBoxIcon枚举类型之一。
例如: MessageBox.Show("平均成绩:" + Convert.ToString(ave), "计算结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
装箱和拆箱:
(1)装箱
装箱是将值类型转换为Object类型或由此值类型实现任一接口类型的过程。将值类型的值装箱操作,就是在堆中分配一个对象实例并将值类型的值复制到该实类中。
例如:int a=15;object b=a;该语句的结果是在堆栈上创建对象引用吧,而在堆上则引用int类型的值。该值时赋给变量a的值类型的一个副本。
(2)拆箱
拆箱是从object类型到值类型或从接口类型到实现该接口的值类型的显示转换。拆线操作包括两个部分:首先检查该对象实例是否是某个给定值的装箱值,然后将该值从实例复制到值类型变量中。
注:要运行时成功拆箱,被拆箱的项必须是对一个对象的引用,该对象是先前通过装箱该值类型的实例创建。