C# 如何从另一个方法c获得主方法

C# 如何从另一个方法c获得主方法,c#,C#,对你们中的一些人来说,这是个业余问题,但我能解决。我知道如何转到程序中的其他方法,因为它们不需要任何参数。当我试图返回到main方法时,我在括号中放了哪些参数 static void writeToFile(string filename, Customer obj, int pos, int size) { FileStream fout; BinaryWriter bw; //create a file stream object fout = new

对你们中的一些人来说,这是个业余问题,但我能解决。我知道如何转到程序中的其他方法,因为它们不需要任何参数。当我试图返回到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
}

ClassName.Main;???你没有。main方法在程序运行开始时执行,并在程序运行结束时终止。如果你想去别的地方,然后回到main,调用一个方法。我很惊讶。您已经问了一些C问题,但您不知道这一点?如果您从主方法调用该方法,请允许它返回。你不需要主叫,你不需要主叫。只需从方法中删除该行代码。您的程序将返回到调用writeToFile的位置,并继续执行writeToFile调用后的代码行writeToFile@..\..\..\Files\Customers.txt、_cust、pos、Record_Size;//方法的结尾然后这将带我到我的WriteToFile方法。。。因此,当它返回时,就没有什么可做的了。。希望你们现在能理解为什么我不能回到main,为什么需要调用它。然后在我的示例中用cust代替WriteToFile,它仍然有效。方法调用可以嵌套;writeToFile将返回到addCust,这将返回到cust,这将返回到Main。抱歉,我无法理解。如果你想说你想打电话给梅因,有没有办法打电话给梅因?你不打电话给梅因。操作系统确实如此。这就是全部。如果你只是让你的方法自然回归,一切都会好起来。这很有帮助,谢谢!
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.
}