对于你们中的一些人来说,这是一个业余问题,但我可以解决这个问题。我知道如何在我的程序中使用其他方法,因为它们不需要任何参数。在尝试回到main方法时,我在括号内放了什么参数?
static void writeToFile(string filename, Customer obj, int pos, int size)
{
FileStream fout;
BinaryWriter bw;
//create a file stream object
fout = new FileStream(filename, FileMode.Open, FileAccess.Write);
//create a binary writer object
bw = new BinaryWriter(fout);
//set file position where to write data
fout.Position = pos * size;
//write data
bw.Write(obj.CustomerNo);
bw.Write(obj.Surname);
bw.Write(obj.Forename);
bw.Write(obj.Street);
bw.Write(obj.Town);
bw.Write(obj.DOB);
//close objects
bw.Close();
fout.Close();
Main(); // what goes inside these parenthesis
}
答案 0 :(得分:3)
public static void main()
{
// do some stuff
// ...
WriteToFile(filename, obj, pos, size);
// ...
// Program execution automatically returns here after WriteToFile is done.
// do some more stuff
// ...
// Program ends. Thank you for playing.
}
static void WriteToFile(string filename, Customer obj, int pos, int size)
{
// yada yada
// No need for a Main() call
// We're done, and about to leave the WriteToFile method. See you later.
}