输入a,b求c = a + b
using System;
using System.Collections.Generic; using System.Text;
namespace Proj2_1 {
class Program {
static void Main(string[] args) {
int a, b, c;
Console.Write(\);
a = int.Parse( Console.ReadLine()); Console.Write(\);
b = int.Parse(Console.ReadLine()); c = a + b;
Console.WriteLine(\, c); } } }
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;
using System.Windows.Forms;
namespace Proj2_2 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
可复制、编制,期待你的好评与关注!
int a, b, c;
a = Convert.ToInt16(textBox1.Text); b = Convert.ToInt16(textBox2.Text); c = a + b;
textBox3.Text = Convert.ToString(c); }
private void Form1_Load(object sender, EventArgs e) {
}
private void textBox2_TextChanged(object sender, EventArgs e) {
} } }
强制转换P38
using System;
using System.Collections.Generic; using System.Text;
namespace Proj3_1 {
class Program {
static void Main(string[] args) {
int i=65,i1,i2;
double d = 66.3456,d1,d2; char c = 'A',c1,c2;
Console.WriteLine(\, i, d, c); i1 = (int)d; //强制类型转换 d1 = i; //隐式类型转换 c1 = (char)i; //强制类型转换
Console.WriteLine(\, i1, d1, c1); i2 = c; //隐式类型转换 d2 = (int)d; //强制类型转换 c2 = (char)d; //强制类型转换
Console.WriteLine(\, i2, d2, c2); } } }
可复制、编制,期待你的好评与关注!
赋值两同学信息数据,并在图中输出结果P44
using System; namespace Proj3_2 { class Program
{ struct Student //类型声明应放在Main函数的外面 { public int xh; //学号 public string xm; //姓名 public string xb; //性别 public int nl; //年龄 public string bh; //班号 }
static void Main(string[] args) { Student s1,s2; //定义两个结构类型变量 s1.xh = 101; s1.xm = \李明\; s1.xb = \男\; s1.nl = 20;
s1.bh = \;
Console.WriteLine(\学号:{0},姓名:{1},性别:{2},年龄:{3},班号:{4}\, s1.xh, s1.xm, s1.xb, s1.nl, s1.bh); s2 = s1; //将结构变量s1赋给s2 s2.xh = 108; s2.xm = \王华\;
Console.WriteLine(\学号:{0},姓名:{1},性别:{2},年龄:{3},班号:{4}\, s2.xh, s2.xm, s2.xb, s2.nl, s2.bh); } } }
声明枚举类型color,给两成员赋值,定义三个变量,赋值运算输出相应值。P47
using System;
using System.Collections.Generic; using System.Text;
namespace Proj3_3 {
class Program {
enum Color { Red=5, Green, Blue, White=1, Black } //类型声明应放在Main函数的外面 static void Main(string[] args) {
Color c1, c2,c3;
Console.WriteLine(\,Color.Red,Color.Green,Color.Blue,Color.White,Color.Black);
Console.WriteLine(\,(int)Color.Red,(int)Color.Gre
可复制、编制,期待你的好评与关注!
en,(
可复制、编制,期待你的好评与关注!
int)Color.Blue,(int)Color.White,(int)Color.Black); c1 = Color.Red; c2 = c1 + 1; c3 = c2 + 1;
Console.WriteLine(\, c1, c2,c3);
Console.WriteLine(\, (int)c1, (int)c2,(int)c3); } } }
位运算符运用P50
using System;
using System.Collections.Generic; using System.Text;
namespace Proj3_4 {
class Program {
static void Main(string[] args) {
byte b1, b2, b3; b1 = 10;
b2 =(byte) ~b1;
Console.WriteLine(b2); b3 = (byte)(b1 << 2); Console.WriteLine(b3); b1 = 3; b2 = 6;
b3 = (byte)(b1 & b2); Console.WriteLine(b3); b3 = (byte)(b1 ^ b2); Console.WriteLine(b3); b3 = (byte)(b1 | b2); Console.WriteLine(b3); } } }
可复制、编制,期待你的好评与关注!