我剛剛開始使用C#,並且我一直在這個問題上停留了兩週。我有一個從類和子類獲取值的主窗體。我的問題是,當我嘗試創建CorporateClass VB的對象時告訴我,我的兩個變量(CarSizeInteger和DiscountInteger)未分配。我的問題是爲什麼。我在程序中早些時候實施了它們。幫幫我!我絕望地卡住了!C#Visual Basic繼承
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)
{
}
}
}
我很想知道你爲什麼認爲把所有的代碼都搞砸了,就像是可以接受的一樣? – ChaosPandion 2012-03-18 05:04:30
對於int變量,後綴「Integer」確實有點不足。 – IanNorton 2012-03-18 11:24:01
僅供參考,在C#中,它以慣用方式命名以小寫字母開頭的局部變量。在C#和VB中都不是一個好主意,用它們的類型命名變量;變量的名稱應該描述它的*目的*,而不是它的存儲。 – 2012-03-18 16:03:59