当我运行程序时,控制台窗口似乎正在运行并关闭。如何保持打开状态以查看结果?
class Program { public class StringAddString { public virtual void AddString() { var strings2 = new string[] { "1", "2", "3", "4", "5","6", "7", "8", "9"}; Console.WriteLine(strings2); Console.ReadLine(); } } static void Main(string[] args) { StringAddString s = new StringAddString(); } }
您忘记了调用您的方法:
static void Main(string[] args) { StringAddString s = new StringAddString(); s.AddString(); }
它应该停止您的控制台,但是结果可能不是您期望的,您应该稍微更改一下代码:
Console.WriteLine(string.Join(",", strings2));