📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinApp数据类型与表达式
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int ix = 0XABCD;
label1.Text = "为ix赋值“0XABCD”后,ix=" + ix + "\n";
//double dx=0XABCD.ef; // 编译错误:“int”并不包含“ef”的定义
//label1.Text += "为dx赋值“0XABCD.ef”后,dx=" + dx + "\n";
float fx = 987654321.12345678f;
label1.Text += "为float类型的fx赋值“987654321.12345678”后,fx=" + fx + "\n";
double dx = 987654321.12345678;
label1.Text += "为double类型的dx赋值“987654321.12345678”后,dx=" + dx + "\n";
decimal mx = 987654321.12345678m;
label1.Text += "为decimal类型的mx赋值“987654321.12345678”后,mx=" + mx + "\n";
DateTime dtx = new DateTime(2006, 5, 30);
label1.Text += "为DateTime类型的dtx赋值“2006,5,30”后,dtx="
+ dtx.ToShortDateString() + "\n";
string s = "X"; char cc = Convert.ToChar(s);
label1.Text += "为char类型的c赋值“string s = \"X\"; char cc = Convert.ToChar(s);”后,cc="
+ cc + "\n";
int a = 3, b = 5, c = -1, d = 7;
label1.Text += "21.设a=3,b=5,c=-1,d=7,求下列逻辑表达式的值。\n";
label1.Text += "(1) a-b/c<d||c>d&&!(c>0)||d<c"
+ "为:" + (a - b / c < d || c > d && !(c > 0) || d < c) + "\n";
label1.Text += "(2) a*d/(c*-a)>d%c||c>=d为:"
+ (a * d / (c * -a) > d % c || c >= d) + "\n";
label1.Text += "(3) (c+d)*(a-b)%2<c &&!(c>b)||d>c为:"
+ ((c + d) * (a - b) % 2 < c && !(c > b) || d > c) + "\n";
label1.Text += "(4) a-b>=c&&b-a>=d为:"
+ (a - b >= c && b - a >= d) + "\n";
//string sx; string sz = sx;
}
private void button2_Click(object sender, EventArgs oe)
{
int e = 1, f = 4, g = 2; float m = 10.5f , n = 4.0f , k ;
label2.Text = "int e = 1, f = 4, g = 2; \nfloat m = 10.5 , n = 4.0 , k ;";
k=(float) ((e + f ) / g + (double ) n * 1.2 / g + m);
label2.Text += "\nk= (e + f ) / g + (double ) n * 1.2 / g + m=" + k;
float x = 2.5f, y = 4.7f; int a = 7;
label2.Text += "\nfloat x = 2.5, y = 4.7; int a = 7;";
label2.Text += "\nx + a % 3 + (int ) (x + y ) % 2 / 4="
+ (x + a % 3 + (int)(x + y) % 2 / 4);
}
private void button3_Click(object sender, EventArgs e)
{
int a = 7, b = -2, c = 4;
label3.Text = "20. 设a=7,b=-2,c=4,求下列表达式的值。";
label3.Text += "\n(1) a+3*c (2) b*2/6 (3) a/2*3/2 (4) a%3+b*b/(float)c/5";
label3.Text += "\n解答:(1)"+(a+3*c)+" (2)"+(b*2/6)
+" (3)"+(a/2*3/2)+" (4)"+(a%3+b*b/(float)c/5);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -