0
我只是創建一個類的對象。這個類的其中一個屬性是另一個類的objcet列表。當我想從第二類對象強制轉換在此列表中此錯誤「不設置到對象的實例對象引用」將得到。對象引用「對象包括列表屬性」
這是第一類的代碼:
public class RCSection<Bar>
{
private string RCSectionName;
private int NumberOfBars;
private double NumberOfInnerBars;
private double NumberOfOuterBars;
private double TransverseSpacing;
private Steel LongitudinalSteel;
private Steel TransevrseSteel;
private Concrete Concrete;
private List<Bar> LongitudinalBar;
private Bar TransverseBar;
private Section Section;
public string rCSectionName
{
set { RCSectionName = value; }
get { return RCSectionName; }
}
public int numberOfBars
{
set { NumberOfBars = value; }
get { return NumberOfBars; }
}
public double transverseSpacing
{
set { TransverseSpacing = value; }
get { return TransverseSpacing; }
}
public double numberOfInnerBars
{
set { NumberOfInnerBars = value; }
get { return NumberOfInnerBars; }
}
public double numberOfOuterBars
{
set { NumberOfOuterBars = value; }
get { return NumberOfOuterBars; }
}
public Steel longitudinalSteel
{
set { LongitudinalSteel = value; }
get { return LongitudinalSteel; }
}
public Steel transverseSteel
{
set { TransevrseSteel = value; }
get { return TransevrseSteel; }
}
public Concrete concrete
{
set { Concrete = value; }
get { return Concrete; }
}
public List<Bar> longitudinalBar
{
set { LongitudinalBar = value; }
get { return LongitudinalBar; }
}
public Bar transverseBar
{
set { TransverseBar = value; }
get { return TransverseBar; }
}
public Section section
{
set { Section = value; }
get { return Section; }
}
}
起初,我想知道,我創建一個屬性列表的方式,是不是? 之後,下面的代碼是使用這個類的對象有關,鑄造一個對象在它
for (int i = 0; i < myRCSection.numberOfBars; i++)
{
Bar mybar = new Bar(newFormRCSection.comboBoxSteelSize1.Text,"SI");
myRCSection.longitudinalBar[i] = mybar;//Error will appear here :(
}