老陈 ASP.NET封装
第一个页面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected void Button1_Click( object sender, EventArgs e) { StreamWriter n1 = File.AppendText( "C:\\n1.txt" ); n1.WriteLine(TextBox1.Text); n1.Close(); StreamWriter n2 = File.AppendText( "C:\\n2.txt" ); n2.WriteLine(TextBox2.Text); n2.Close(); StreamWriter n3 = File.AppendText( "C:\\n3.txt" ); n3.WriteLine(TextBox3.Text); n3.Close(); ListBox1.Items.Add(TextBox1.Text + TextBox2.Text + TextBox3.Text + "\n" ); TextBox1.Text = "" ; TextBox2.Text = "" ; TextBox3.Text = "" ; } protected void Button2_Click( object sender, EventArgs e) { //跳转页面 Response.Redirect( "Default2.aspx" ); } } |
第二个页面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; public partial class Default2 : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } //开始 public static int Count = 0; public static int right = 0; //总计的个数和正确的个数 int m = 0; protected void Button1_Click( object sender, EventArgs e) { //出题 string [] n1 = new string [100]; n1 = File.ReadAllLines( "C:\\n1.txt" ); TextBox1.Text = n1[m]; string [] n2 = new string [100]; n2 = File.ReadAllLines( "C:\\n2.txt" ); TextBox2.Text = n2[m]; string [] n3 = new string [100]; n3 = File.ReadAllLines( "C:\\n3.txt" ); TextBox3.Text = n3[m]; m++; } protected void Button2_Click( object sender, EventArgs e) { TextBox4.Enabled = false ; Response.Write( "运算结束!" ); TextBox5.Text = Default2.Count.ToString(); //题目总数 TextBox6.Text = Default2.right.ToString(); TextBox7.Text = ((Default2.right / ( double )(Default2.Count)) * 100).ToString() + "%" ; //正确率 } protected void Button4_Click( object sender, EventArgs e) { int a = int .Parse(TextBox1.Text); int b = int .Parse(TextBox3.Text); Char c = Convert.ToChar(TextBox2.Text); Class1 con = new Class1(); con.chu(a, b, c); if (con.answer == int .Parse(TextBox4.Text)) { Response.Write( "回答正确!下一题请按开始按钮!" ); right++; Count++; } else { Response.Write( "回答错误!下一题请按开始按钮!" ); Count++; } } } |
.net的封装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> ///Class1 的摘要说明 /// </summary> public class Class1 { public Class1() { // //TODO: 在此处添加构造函数逻辑 // } public int sum; public int answer { get { return sum; } } public int chu( int n1, int n2, char fuhao) { if (fuhao == '+' ) { return sum = n1 + n2; } else if (fuhao == '-' ) { return sum = n1 - n2; } else if (fuhao == '*' ) { return sum= n1 * n2; } return sum; } } |
运行后
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步