想要自己写一个计算器应用程序,费了大概一天的时间,结果还是在高人的指点下才完成(在这里谢谢一直辅导我的哥哥),原来代码不是那么好些的,自己以后要尝试多写一些,大胆,不要怕错,细心调试,慢慢更改,我相信一定行的!加油!!!自己是最棒的!!!!
为什么说是简单数字计算器,应为这个计算器还不能够辨别数字和汉字,只能输入纯数字以进行加减乘除简单运算,随着学习的更进一步深入,会更加完善!
html代码:

c# asp.net 简单数字计算器(4)<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="计算器._Default" %>
c# asp.net 简单数字计算器(4)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
c# asp.net 简单数字计算器(4)
<html xmlns="http://www.w3.org/1999/xhtml" >
c# asp.net 简单数字计算器(4)<head runat="server">
c# asp.net 简单数字计算器(4)        <title>简单计算器</title>
c# asp.net 简单数字计算器(4)</head>
c# asp.net 简单数字计算器(4)<body>
c# asp.net 简单数字计算器(4)        <form ></html>

后台c#代码:

c# asp.net 简单数字计算器(4)using System;
c# asp.net 简单数字计算器(4)using System.Collections;
c# asp.net 简单数字计算器(4)using System.Configuration;
c# asp.net 简单数字计算器(4)using System.Data;
c# asp.net 简单数字计算器(4)using System.Linq;
c# asp.net 简单数字计算器(4)using System.Web;
c# asp.net 简单数字计算器(4)using System.Web.Security;
c# asp.net 简单数字计算器(4)using System.Web.UI;
c# asp.net 简单数字计算器(4)using System.Web.UI.HtmlControls;
c# asp.net 简单数字计算器(4)using System.Web.UI.WebControls;
c# asp.net 简单数字计算器(4)using System.Web.UI.WebControls.WebParts;
c# asp.net 简单数字计算器(4)using System.Xml.Linq;
c# asp.net 简单数字计算器(4)
namespace 计算器
c# asp.net 简单数字计算器(4){
c# asp.net 简单数字计算器(4) public partial class _Default : System.Web.UI.Page
c# asp.net 简单数字计算器(4)        {
c# asp.net 简单数字计算器(4) protected void Page_Load(object sender, EventArgs e)
c# asp.net 简单数字计算器(4)                {
c# asp.net 简单数字计算器(4)
                }
c# asp.net 简单数字计算器(4)
protected void Button1_Click(object sender, EventArgs e)
c# asp.net 简单数字计算器(4)                {
c# asp.net 简单数字计算器(4) int nu1 = int.Parse(this.num1.Text.ToString());//对nu1从string转为int型。
c# asp.net 简单数字计算器(4) int nu2 = int.Parse(this.num2.Text.ToString());
c# asp.net 简单数字计算器(4) int sum = 0;//对sum进行初始化
c# asp.net 简单数字计算器(4) string n = this.dropdownlist.SelectedItem.Text.ToString();//选择下拉单选框中选择在aspx源中的+,-,*,/。
c# asp.net 简单数字计算器(4)
c# asp.net 简单数字计算器(4) switch (n)
c# asp.net 简单数字计算器(4)                        {
c# asp.net 简单数字计算器(4) case ("+"):
c# asp.net 简单数字计算器(4)                                        sum = nu1 + nu2;
c# asp.net 简单数字计算器(4) break;
c# asp.net 简单数字计算器(4) case "-":
c# asp.net 简单数字计算器(4)                                     sum = nu1 - nu2;
c# asp.net 简单数字计算器(4) break;
c# asp.net 简单数字计算器(4) case "*":
c# asp.net 简单数字计算器(4)                                     sum = nu1 * nu2;
c# asp.net 简单数字计算器(4) break;
c# asp.net 简单数字计算器(4) case "/":                                    
c# asp.net 简单数字计算器(4)                                        sum = nu1 / nu2;
c# asp.net 简单数字计算器(4) break;
c# asp.net 简单数字计算器(4) default:
c# asp.net 简单数字计算器(4)                                        Console.WriteLine("请正确输入数字");
c# asp.net 简单数字计算器(4) break;
c# asp.net 简单数字计算器(4)                        }
c# asp.net 简单数字计算器(4) this.Label1.Text = sum.ToString();//在空间label中显示sum的值。
c# asp.net 简单数字计算器(4)
c# asp.net 简单数字计算器(4)                }
c# asp.net 简单数字计算器(4)        }
c# asp.net 简单数字计算器(4)}

相关文章:

  • 2021-12-26
  • 2021-04-14
  • 2022-12-23
  • 2021-12-04
  • 2021-11-15
  • 2022-03-06
  • 2022-12-23
猜你喜欢
  • 2022-01-14
  • 2021-09-03
  • 2022-12-23
  • 2021-10-16
  • 2021-12-04
  • 2021-08-22
相关资源
相似解决方案