Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 方法必须具有返回类型,调试时不显示任何内容_C#_Winforms - Fatal编程技术网

C# 方法必须具有返回类型,调试时不显示任何内容

C# 方法必须具有返回类型,调试时不显示任何内容,c#,winforms,C#,Winforms,我构建了这段代码,试图显示一个有3个选项的列表框,然后combox为您可以选择的选项添加了内容,如果您想要糖或奶油,也有一个复选框,然后尝试在文本框中显示总成本,然后在消息框中显示或订购按钮 我的问题是我的form1\u加载(必须有返回类型),当我尝试调试时,表单显示为空。 这是我的全部代码。任何帮助都将不胜感激 using System; using System.Collections.Generic; using System.ComponentModel; using System.Da

我构建了这段代码,试图显示一个有3个选项的列表框,然后combox为您可以选择的选项添加了内容,如果您想要糖或奶油,也有一个复选框,然后尝试在文本框中显示总成本,然后在消息框中显示或订购按钮

我的问题是我的form1\u加载(必须有返回类型),当我尝试调试时,表单显示为空。 这是我的全部代码。任何帮助都将不胜感激

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

namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
    }
    public class Order
    {
        public string[] menuSelection = new
               string[] { "Coffee", "Tea", "Pastry" };

        public decimal[] menuSelectionPrice = new
                decimal[] { 2.75m, 1.25m, 2.00m };

        private string selection;
        private bool cream;
        private string specialRequest;
        private decimal selectionPrice;
        private decimal specialPrice;

        public Order()
        {
            selection = " ";
            cream = false;
            specialRequest = "";
            selectionPrice = 0;
            drinkPrice = 0;
        }
        // property for selection
        public string Selection
        {
            get
            {
                return selection;
            }
            set
            {
                selection = value;
                SetSelectionPrice();
            }
        }
        // Property for special request 
        public string SpecialRequest
        {
            get
            {
                return specialRequest;
            }
            set
            {
                specialRequest = value;
                SetSpecialPrice();
            }
        }
        public bool Cream
        {
            set
            {
                cream = value;
            }
        }
        // read only property for  selection price
        public decimal SelectionPrice
        {
            get
            {
                return selectionPrice;
            }
        }
        // after the selection is set, store the selection price
        public void SetSelectionPrice()
        {
            for (int i = 0 < menuSelection.Length; i++)
            {
                if (menuSelection[i] == selection)
                {
                    selectionPrice = menuSelectionPrice[i];
                }
            }
        }
        // Return the Cream Selection.
        public string GetCreamSelection()
        {
            string creamOrNot;
            if (cream)
            {
                creamOrNot = "Cream";
            }
            else
            {
                creamOrNot = "No Cream";
            }
               return creamOrNot;
        }
        public decimal SpecialPrice
        {
            get
            {
                return specialPrice;
            }
        }
        public void SetSpecialPrice()
        {
            switch (specialRequest)
            {
                case "Cinnamon":
                    specialPrice = 0.50m;
                    break;
                case "Cocoa":
                    specialPrice = 1.00m;
                    break;
                case "Whipped Cream":
                    specialPrice = 0.74m;
                    break;
                case "Lemon" :
                case "Cherry" :
                case "Chocolate" :
                case "Pineapple" :
                case "Peach" :
                case "Strawberry" :
                case "Cheese" :
                case "Watermellon" :
                case "Apple" :
                case "Orange" :
                    specialPrice = 2.00m;
                    break;

            }
        }
        public decimal DetermineTotalCost() 
        {
            return selectionPrice + specialPrice;
        }
        public override string ToString()
        {
            return "Total Due: " + DetermineTotalCost().ToString("C");
        }
    }
     public void Form1_Load(object sender,System.EventArgs e)
     {
         newOrder = new Order();
         for (int i = 0; i < newOrder.menuSelection.Length; i++)
         {
             this.lstBxChoice.Items.Add(newOrder.menuSelection[i]);
         }
     }

    private void lstBxChoice_SelectedIndexChanged(object sender, EventArgs e)
    {
        newOrder.Selection = this.lstBxChoice.Text;
    }

    private void cmbSpecial_SelectedIndexChanged(object sender, EventArgs e)
    {
        newOrder.SpecialRequest =this.cmboSpecial.Text;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        MessageBox.Show(newOrder.Selection + "\n" +  newOrder.SpecialRequest + "\n" + newOrder.GetCreamSelection());
    }

    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (this.checkBox1.Checked)
            newOrder.cream = true;
        else
            newOrder.cream = false;
    }





}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
单系统绘图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间Windows窗体应用程序6
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
公共阶级秩序
{
公共字符串[]菜单选择=新建
字符串[]{“咖啡”、“茶”、“糕点”};
公共十进制[]菜单选择价格=新
十进制[]{2.75米、1.25米、2.00米};
私有字符串选择;
私用布尔乳膏;
私有字符串特殊请求;
私有十进制选择价格;
私人十进制特殊价格;
公共秩序()
{
选择=”;
奶油=假;
specialRequest=“”;
selectionPrice=0;
饮用水价格=0;
}
//用于选择的属性
公共字符串选择
{
得到
{
返回选择;
}
设置
{
选择=价值;
SetSelectionPrice();
}
}
//特殊要求的财产
公共字符串特殊请求
{
得到
{
返回特殊请求;
}
设置
{
特殊要求=价值;
设置特殊价格();
}
}
公共奶油
{
设置
{
奶油=价值;
}
}
//选择价格的只读属性
公共十进制选择价格
{
得到
{
返回选择价格;
}
}
//设置选择后,存储选择价格
公共无效设置选择价格()
{
for(int i=0

}

您的选择应该返回字符串

首先,您应该全局创建Order的实例

 newOrder = new Order();
第二,

  public string GetCreamSelection()
    {
        string creamOrNot;
        if (cream)
        {
            creamOrNot = "Cream";
        }
        else
        {
            creamOrNot = "No Cream";
        }
        return creamOrNot;
    }

不管我怎么想void问题,我的错误是newOrder在当前上下文中不存在。错误6'WindowsFormsApplication6.Form1.Order.GetCreamSelection()':并非所有代码路径都返回一个值C:\Users\zach\Documents\Visual Studio 2012\Projects\WindowsFormsApplication6\WindowsFormsApplication6\caffee.cs 95 27 WindowsFormsApplication6不确定如何修复,这并没有很不幸地解决该问题,再次检查你的代码我仍然有newOrder错误。我添加了返回值creamOrNot。将其写在代码顶部,上面的表单初始化newOrder=newOrder