By declaring a parameter out, you will “promise” the caller (and the compiler) that your method will set the value of the variable provided as an argument to that parameter.
, .
tourists. NullReferenceException at tourists.Add(...), null.
, out tourists Main. , ReadData , , tourists. ( ), out.
, ReadData ,
tourists = new List<Tourist>()
ReadData foreach.
, ommit ReadData, :
static List<Tourist> ReadData()
{
List<Tourist> tourists = new List<Tourist>();
const string Input = "..\\..\\Duomenys.txt";
string[] lines = File.ReadAllLines(Input);
foreach (string line in lines)
{
tourists.Add(new Tourist(firstName, lastName, money));
}
return tourists;
}
Main :
static void Main(string[] args)
{
List<Tourist> tourists = ReadData();
}