如何保持控制台窗口打开 [英] How to keep console window open

查看:166
本文介绍了如何保持控制台窗口打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的程序,控制台窗口似乎运行和关闭。如何保持开放,使我能看到的结果吗?

 类节目
{
公共类StringAddString
{
公共虚拟无效AddString()
{
变种strings2 =新的字符串[] {1,2,3,4,5,6,7,8 ,9};

Console.WriteLine(strings2);
到Console.ReadLine();
}
}

静态无效的主要(字串[] args)
{
StringAddString S =新StringAddString();
}
}


解决方案

您忘记调用你的方法:

 静态无效的主要(字串[] args)
{
StringAddString S =新StringAddString();
s.AddString();
}



应停止控制台,但结果可能不是你所期望的,你应该改变你的代码一点点:

  Console.WriteLine(的string.join(,,strings2)); 


When I run my program, the console window seems to run and close. How to keep it open so I can see the results?

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();            
    }
}

解决方案

You forgot calling your method:

static void Main(string[] args)
{          
    StringAddString s = new StringAddString();  
    s.AddString();
}

it should stop your console, but the result might not be what you expected, you should change your code a little bit:

Console.WriteLine(string.Join(",", strings2));

这篇关于如何保持控制台窗口打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆