错误CS1026和错误CS1061 [英] Error CS1026 and error CS1061

查看:155
本文介绍了错误CS1026和错误CS1061的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为课程建立一个餐馆账单计算器,但我遇到了一些我无法弄清楚如何解决的错误。错误CS1026在错误列表中指出它是预期的。错误CS1061在错误列表中指出'TextBox'不包含'Items'的定义,并且没有扩展方法'Items'可以找到接受类型'TextBox'的第一个参数(你是否缺少using指令或程序集)参考?)。项目列在ComboBoxes中...我无法弄清楚如何修复这些错误Dx。请帮助我,谢谢!

这是我对餐馆账单计算器的编码:

 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;

命名空间 Restaurant_Bill_Calculator
{

public partial class RestaurantBillCalculator:表格
{
public struct 订单
{
public < span class =code-keyword> string item;
public double 价格;
}

const double TAX = 0 06 ; // 6%税
订单订单= 订单();
static double subtotal = 0 ;
static double totalTaxes = 0 ;
static double total = 0 ;
string finalBill = 最终条例草案:\\ \
;

public RestaurantBillCalculator()
{
InitializeComponent();
}

private void getValues( string custOrder)
{
order.item = custOrder.Split(' $')[ 0 ];
order.price = Convert.ToDouble(custOrder.Split(' $')[< span class =code-digit> 1
];
Output.Items.Add( 价格: + order.price);
finalBill + = Ordered Item: + order.item + \ nPrice: + order.price.ToString( C2)+ \ n;
updateBill();
}

private void updateBill()
{
小计+ = order.price;
总计+ = order.price +(订单.price * TAX);
totalTaxes + = order.pric e * TAX;
{

}

Output.Items.Clear();
Output.Items.AddRange(finalBill.Split(' \ n'));
Output.Items.Add( 小计: + subtotal.ToString( C2));
Output.Items.Add( Tax: + totalTaxes.ToString( C2));
Output.Items.Add( 总计: + total.ToString( C2));
}

private void RestaurantBillCalculator_Load( object sender,EventArgs e)
{

}

private void dropdownSelection( object sender,EventArgs e)
{
if (sender == cmbdrinks)
getValues(cmbdrinks.SelectedItem.ToString());
else if (sender == cmbappetizers)
getValues(cmbappetizers.SelectedItem。的ToString());
else if (sender == cmbmaincourses)
getValues(cmbmaincourses.SelectedItem。的ToString());
else
getValues(cmbdrinks.SelectedItem.ToString());
}

private void Output_TextChanged( object sender,EventArgs e)
{
}

private void Clear_Click( object sender,EventArgs e)
{
}
}
}





我的尝试:



我试图在线找到解决方案,但没有解决方案适合我的问题...

解决方案

')[< span class =code-digit> 0 ];
order.price = Convert.ToDouble(custOrder.Split('


< blockquote>')[ 1 ];
Output.Items.Add( 价格: + order.price);
finalBill + = Ordered Item: + order.item + \ nPrice: + order.price.ToString( C2)+ \ n;
updateBill();
}

private void updateBill()
{
subtotal + = order.price;
total + = order.price +(order.price * TAX);
totalTaxes + = order.price * TAX;
{

}

Output.Items.Clear();
Output.Items.AddRange(finalBill.Split(' \ n'));
Output.Items.Add( 小计: + subtotal.ToString( C2));
Output.Items.Add( Tax: + totalTaxes.ToString( C2));
Output.Items.Add( 总计: + total.ToString( C2));
}

private void RestaurantBillCalculator_Load( object sender,EventArgs e)
{

}

private void dropdownSelection( object sender,EventArgs e)
{
if (sender == cmbdrinks)
getValues(cmbdrinks.SelectedItem.ToString());
else if (sender == cmbappetizers)
getValues(cmbappetizers.SelectedItem。的ToString());
else if (sender == cmbmaincourses)
getValues(cmbmaincourses.SelectedItem。的ToString());
else
getValues(cmbdrinks.SelectedItem.ToString());
}

private void Output_TextChanged( object sender,EventArgs e)
{
}

private void Clear_Click( object sender,EventArgs e)
{
}
}
}





我的尝试:



我试图在线找到解决方案,但没有解决方案适合我的问题...


仔细检查输出是什么类型的控件。我想你会发现它是一个文本框,而不是一个组合框。并且TextBox没有Items属性。



第37行 - 你错过了一个封闭的括号。你有两个开放式括号,只有一个已关闭。


I am trying to build a Restaurant Bill Calculator for class, but I am experiencing a few errors that I can't figure out how to fix. The Error CS1026 states in the error list that it was "expected". The Error CS1061 states in the Error list that 'TextBox' does not contain a definition for 'Items' and no extension method 'Items' accepting a first argument of type 'TextBox' could be found (are you missing a using directive or an assembly reference?). Items is listed in the ComboBoxes... I can't figure out how to fix these errors Dx. Please assist me and thank you!
Here is my coding for the Restaurant Bill Calculator:

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

    public partial class RestaurantBillCalculator : Form
    {
        public struct Orders
        {
            public string item;
            public double price;
        }

        const double TAX = 0.06; //6% tax
        Orders order = new Orders();
        static double subtotal = 0;
        static double totalTaxes = 0;
        static double total = 0;
        string finalBill = "FINAL BILL: \n";

        public RestaurantBillCalculator()
        {
            InitializeComponent();
        }

        private void getValues(string custOrder)
        {
            order.item = custOrder.Split('$')[0];
            order.price = Convert.ToDouble(custOrder.Split('$')[1];
            Output.Items.Add("Price: " + order.price);
            finalBill += "Ordered Item: " + order.item + "\nPrice: " + order.price.ToString("C2") + "\n";
            updateBill();
        }

        private void updateBill()
        {
            subtotal += order.price;
            total += order.price + (order.price * TAX);
            totalTaxes += order.price * TAX;
            {

            }

            Output.Items.Clear();
            Output.Items.AddRange(finalBill.Split('\n'));
            Output.Items.Add("Subtotal: " + subtotal.ToString("C2"));
            Output.Items.Add("Tax: " + totalTaxes.ToString("C2"));
            Output.Items.Add("Total: " + total.ToString("C2"));
        }

        private void RestaurantBillCalculator_Load(object sender, EventArgs e)
        {

        }

        private void dropdownSelection(object sender, EventArgs e)
        {
            if (sender == cmbdrinks)
                getValues(cmbdrinks.SelectedItem.ToString());
            else if (sender == cmbappetizers)
                getValues(cmbappetizers.SelectedItem.ToString());
            else if (sender == cmbmaincourses)
                getValues(cmbmaincourses.SelectedItem.ToString());
            else
                getValues(cmbdrinks.SelectedItem.ToString());
        }

        private void Output_TextChanged(object sender, EventArgs e)
        {
        }

        private void Clear_Click(object sender, EventArgs e)
        {
        }
    }
}



What I have tried:

I have tried to find a solution online, but no solution has fit my issue...

解决方案

')[0]; order.price = Convert.ToDouble(custOrder.Split('


')[1]; Output.Items.Add("Price: " + order.price); finalBill += "Ordered Item: " + order.item + "\nPrice: " + order.price.ToString("C2") + "\n"; updateBill(); } private void updateBill() { subtotal += order.price; total += order.price + (order.price * TAX); totalTaxes += order.price * TAX; { } Output.Items.Clear(); Output.Items.AddRange(finalBill.Split('\n')); Output.Items.Add("Subtotal: " + subtotal.ToString("C2")); Output.Items.Add("Tax: " + totalTaxes.ToString("C2")); Output.Items.Add("Total: " + total.ToString("C2")); } private void RestaurantBillCalculator_Load(object sender, EventArgs e) { } private void dropdownSelection(object sender, EventArgs e) { if (sender == cmbdrinks) getValues(cmbdrinks.SelectedItem.ToString()); else if (sender == cmbappetizers) getValues(cmbappetizers.SelectedItem.ToString()); else if (sender == cmbmaincourses) getValues(cmbmaincourses.SelectedItem.ToString()); else getValues(cmbdrinks.SelectedItem.ToString()); } private void Output_TextChanged(object sender, EventArgs e) { } private void Clear_Click(object sender, EventArgs e) { } } }



What I have tried:

I have tried to find a solution online, but no solution has fit my issue...


Double check what type of control "Output" is. I think you'll find it is a textbox, not a combobox. And a TextBox does not have an Items property.

And line 37 - you're missing a closed bracket. You have two open brackets, and only one closed.


这篇关于错误CS1026和错误CS1061的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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