Returning a string from a console application

前端 未结 2 1016
走了就别回头了
走了就别回头了 2020-12-11 15:00

What I really want to do is this

static string Main(string[] args)

but that doesn\'t work, your only options are void and

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 15:27

    Is this in fact the ONLY way to do this, or is there something different/better I can use?

    This isn't the only way to do this, but it is the most common.

    The other options would involve some form of interprocess communication, which is likely going to be significantly more development effort for a single string.

    Note that, if the calling application is a .NET application, and you have control over both applications, it might make more sense to just write a class library instead of a console application. This would allow you to keep the code completely separate, but have the executable "call into" your library to get the string data.

提交回复
热议问题