无法获取消息框以使用for循环在方法中工作

时间:2016-03-02 14:38:52

标签: c#

我已经让该程序正常工作,但是我必须在其中添加一个消息框告诉用户他输入了错误的数字或说明,我似乎无法使其正常工作。这是我的代码:

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

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

        private void btnPrice_Click(object sender, EventArgs e)
        {
            int [] itemNum = { 112, 123, 134, 213, 224, 235 };
            double[] price = { 16.95, 10.95, 14.25, 21.95, 45.99, 89.99 };
            string[] description = { "plate", "cup", "bowl", "vase", "planter", "statue" };

            string getstrItem;
            int getintItem;

            getstrItem = Convert.ToString(txtOrder.Text);
            bool isNumerical = int.TryParse(getstrItem, out getintItem);
            getDetails(getintItem,itemNum,price);
            getDetails(getstrItem, description, price);

        }
        public void getDetails(int itemNumber, int [] item, double [] metPrice )
        {
            bool statement = false;

            for (int index = 0; index < item.Length; ++index)
            {
                if (itemNumber == item[index])
                {
                    txtDetails.Text = string.Format("Item number is {0} and price is {1}", itemNumber, metPrice[index]);
                    statement = true;
                }
            }
        }
        private void getDetails(string itemNumber, string[] description, double [] Price )
        {
            for (int index = 0; index < description.Length; ++index)
            {
                if (itemNumber == description[index])
                    txtDetails.Text = string.Format("The item description is {0} and price is {1}", description[index], Price[index]);
            }      
        }

    }
}

我尝试了一个else语句,但当我注意到它只是跳过第一个if语句时,因为它是错误的数字去了else。

立即放入消息框,即使我在其中输入了正确的数字,也会在文本框中显示正确的内容,然后放上消息框。

0 个答案:

没有答案