私は C# を使い始めたばかりで、この問題に 2 週間悩まされています。クラスとサブクラスから値を取得するメイン フォームがあります。私の問題は、CorporateClass VB のオブジェクトを作成しようとすると、2 つの変数 (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)
{
}
}
}