【问题标题】:punctuation expected errors-c# [closed]标点符号预期错误-c# [关闭]
【发布时间】:2012-10-07 11:22:35
【问题描述】:

我是 c# 的新手。我尝试编写基本平均计算器。我得到了 60 个错误,其中大部分是

) 预期

;预计

我检查过,但我认为一切都是正确的。我使用 Visual Studio 2010 会有问题吗?

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 WindowsFormsApplication3
    {

            public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                double a;
                a = ((Convert.ToInt16(textBox1.Text) * 0.4) + (Convert.ToInt16(textBox2.Text) * 0.6));
                if (a >= 50 & a < 60 & Convert.ToInt64(textBox2.Text) >= 50)
                {
                    label4.Text = "Geçti";
                    label5.Text = "CC";
                    textBox3.Text = a.ToString();
                }

                else
                {
                    label4.Text = "KALDI";
                    label5.Text = "FF";
                    textBox3.Text = a.ToString();            
                }

            }



                private void button2_Click_1(object sender, EventArgs e)
                {
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                label4.Text = "Durum";
                label5.Text = "Sonuc";
                }


        }



        }

【问题讨论】:

标签: c# punctuation


【解决方案1】:

代码中有 HTML 实体,必须将其转换回真实字符。

例如:

if (a >= 50 & a < 60 & Convert.ToInt64(textBox2.Text) >= 50)

应该是:

if (a >= 50 & a < 60 & Convert.ToInt64(textBox2.Text) >= 50)

【讨论】:

    【解决方案2】:
    private void button1_Click(object sender, EventArgs e)
    {
        double a;
        a = ((Convert.ToInt16(textBox1.Text) * 0.4) + (Convert.ToInt16(textBox2.Text) * 0.6));
        if (a >= 50 && a < 60 && Convert.ToInt64(textBox2.Text) >= 50)
        {
            label4.Text = "Ge&ccedil;ti";
            label5.Text = "CC";
            textBox3.Text = a.ToString();
        }
        else
        {
            label4.Text = "KALDI";
            label5.Text = "FF";
            textBox3.Text = a.ToString();            
        }
    }
    
    private void button2_Click_1(object sender, EventArgs e)
    {
        textBox1.Text = "";
        textBox2.Text = "";
        textBox3.Text = "";
        label4.Text = "Durum";
        label5.Text = "Sonuc";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-19
      • 2020-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多