错误:值不能为空。参数名称:String [英] error: Value cannot be null. Parameter name: String

查看:166
本文介绍了错误:值不能为空。参数名称:String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        string s1, s2,oper;
        public Form1()
        {
            InitializeComponent();
        }

        private void btn0_Click(object sender, EventArgs e)
        {
            textBox1.Text += btn0.Text;
        }

        private void btn1_Click(object sender, EventArgs e)
        {
            textBox1.Text += btn1.Text;
        }

        private void btn2_Click(object sender, EventArgs e)
        {
            textBox1.Text += btn2.Text;
        }

        private void btn3_Click(object sender, EventArgs e)
        {
            textBox1.Text += btn3.Text;
        }

        private void btn4_Click(object sender, EventArgs e)
        {
            textBox1.Text += btn4.Text;
        }

        private void btn5_Click(object sender, EventArgs e)
        {
            textBox1.Text += btn5.Text;
        }

        private void btn6_Click(object sender, EventArgs e)
        {
            textBox1.Text += btn6.Text;
        }

        private void BTn7_Click(object sender, EventArgs e)
        {
            textBox1.Text += BTn7.Text;
        }

        private void btn8_Click(object sender, EventArgs e)
        {
            textBox1.Text += btn8.Text;
        }

        private void btn9_Click(object sender, EventArgs e)
        {
            textBox1.Text += btn9.Text;
        }

        private void btnpoint_Click(object sender, EventArgs e)
        {
            string s = textBox1.Text;
            int j = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '.')
                {
                    j = 0;
                    break;


                }
                else
                {
                    j = 1;
                }

             }
            if (j == 1)
            {
                textBox1.Text += btnpoint.Text;
            }
        }

        private void btnPlus_Click(object sender, EventArgs e)
        {
            string s1 = textBox1.Text;
            textBox1.Text = "";
            oper = "+";

        }

        private void btneql_Click(object sender, EventArgs e)
        {
            int e1;
            double equal;
            if (oper == "+")
            {
                string s = textBox1.Text;
                int j = 0;
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i] == '.')
                    {
                        j = 0;
                        break;


                    }
                    else
                    {
                        j = 1;
                    }

                }
                if (j == 1)
                {
                    string s2 = textBox1.Text;
                    e1 = int.Parse(s1) + int.Parse(s2);
                    textbox1.text=e1.ToString();
                }
                else
                {
                    string s2 = textBox1.Text;
                    equal = double.Parse(s1) + double.Parse(s2);
                     textbox1.text=equal.ToString();
                }
            }
        }
    }
}

在这个计算器程序中,当我尝试添加两个数字而不是出现错误时价值不能参数名称:字符串

请告诉我如何删除它?

In this calculator program when i try to add two number than error is coming "Value cannot be null. Parameter name: String"
please tell me how can i remove it??

推荐答案

问题已解决

实际上我两次定义字符串s1和s2
problem has been resolved
actually i define string s1 and s2 two times


这篇关于错误:值不能为空。参数名称:String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆