我刚刚开始使用 C#,我已经被这个问题困住了两个星期。我有一个从类和子类获取值的主表单。我的问题是,当我尝试创建 CorporateClass 的对象时,VB 告诉我我的两个变量(CarSizeInteger 和 DiscountInteger)未分配。我的问题是为什么。我在程序的早期实现了它们。帮助!我绝望地被困住了!
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 EX02_CarRentals
{
public partial class RentalForm : Form
{
public RentalForm()
{
InitializeComponent();
}
private void CloseButton_Click(object sender, EventArgs e)
{
Close();
}
private void CalculateButton_Click(object sender, EventArgs e)
{
int DaysInteger, BeginningOdometerInteger, EndingOdometerInteger, CarSizeInteger, DiscountInteger;
if (LicenseTextBox.Text != "")
if (CompactRadioButton.Checked || MidSizeRadioButton.Checked || LuxuryRadioButton.Checked)
{
int.TryParse(DaysRentedTextBox.Text, out DaysInteger);
int.TryParse(BeginningOdometerTextBox.Text, out BeginningOdometerInteger);
if (BeginningOdometerInteger > 0)
{
int.TryParse(EndingOdometerTextBox.Text, out EndingOdometerInteger);
if (EndingOdometerInteger > 0)
{
if (CompactRadioButton.Checked)
CarSizeInteger = (int)CarSize.Compact;
else if (MidSizeRadioButton.Checked)
CarSizeInteger = (int)CarSize.MidSize;
else CarSizeInteger = (int)CarSize.Luxury;
}
{
if (CorporateRadioButton.Checked || InsuranceRadioButton.Checked)
{
if (CorporateRadioButton.Checked)
DiscountInteger = (int)Discount.Corporate;
else if (InsuranceRadioButton.Checked)
DiscountInteger = (int)Discount.Insurance;
//create an instance of the Corporate Class
CorporateClass aCorpRental = new CorporateClass(BeginningOdometerInteger, EndingOdometerInteger, CarSizeInteger, DaysInteger, DiscountInteger);
AmountDueTextBox.Text = (aCorpRental.getAmountDue()).ToString("C");
}
else
{
//create an instance of the Rental Class
RentalRate ARental = new RentalRate(BeginningOdometerInteger, EndingOdometerInteger, CarSizeInteger, DaysInteger);
AmountDueTextBox.Text = (ARental.getAmountDue()).ToString("C");
}
}
}
}
}
}
private void DaysRentedTextBox_TextChanged(object sender, EventArgs e)
{
}
}
}