我有2个文件,一个包含:不能在主类中的其他类达到列表
namespace Vluchten_Boeken
{
public class Vluchten
{
public string FlightNr;
public string FlightCarrier;
public string Destination;
public int maxPassagers;
public int bookedPassagers;
public Vluchten(string _FlightNr, string _FlightCarrier, string _Destination, int _maxPassagers, int _bookedPassagers)
{
this.FlightNr = _FlightNr;
this.FlightCarrier = _FlightCarrier;
this.Destination = _Destination;
this.maxPassagers = _maxPassagers;
this.bookedPassagers = _bookedPassagers;
}
}
}
其他文件包括:
namespace Vluchten_Boeken
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
Console.Write("");
foreach (Vluchten Vluchten in vluchtList)
{
Console.WriteLine(vluchtList);
}
}
}
}
不过,我可以很容易做到的一个foreach
循环列表,该列表中,但是当我尝试这样做的其他文件,我得到
Error 1 The name 'vluchtList' does not exist in the current context
这是相同的文件可能是一个简单的解决方法,也许我一直在使用谷歌搜索错误的东西,但我无法解决它。
谷歌“变量范围” – 2014-11-06 17:03:47
我用尽我的列表设置为公开,但只给了我更多的错误.. – Hocho 2014-11-06 17:05:07
你从来没有宣布'vluchtList'。它应该是什么? – Andrew 2014-11-06 17:05:32