无法在c#console应用程序中运行hello world程序

时间:2012-04-14 09:57:28

标签: c#

我正在学习C#并为控制台应用程序运行hello world程序。当我使用f5运行时,控制台会弹出并立即消失。

    using System;

namespace CSharpConsoleApps
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("hello c sharp world ");
        }
    }
}

以下是它在输出中显示的消息

'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\skumar\Documents\Visual Studio 2010\Projects\CSharpConsoleApps\CSharpConsoleApps\bin\Debug\CSharpConsoleApps.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread '<No Name>' (0x12b0) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x674) has exited with code 0 (0x0).
'CSharpConsoleApps.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\skumar\Documents\Visual Studio 2010\Projects\CSharpConsoleApps\CSharpConsoleApps\bin\Debug\CSharpConsoleApps.exe', Symbols loaded.
The thread 'vshost.RunParkingWindow' (0xdd8) has exited with code 0 (0x0).
The thread '<No Name>' (0x1424) has exited with code 0 (0x0).
The program '[4320] CSharpConsoleApps.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

3 个答案:

答案 0 :(得分:20)

您的程序执行成功,但控制台立即关闭。

为防止这种情况发生,请使用Ctrl+F5而不是F5

答案 1 :(得分:6)

这正如你所说的那样奏效!

基本上,该代码只是说“显示此行文本”。所以一旦完成,没有别的事可做,它就会停止运行。

尝试添加

Console.ReadKey();

再次运行

答案 2 :(得分:1)

计算机完全他们编程要做的事情。在这种情况下,原始代码没有指示计算机在终止之前等待来自用户的输入。因此,计算机在出现时按照说明进行操作,并正常终止程序。

你可以尝试:

namespace CSharpConsoleApps
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("hello c sharp world ");
            Console.ReadLine();
        }
    }
}

再次运行它。然后,在关闭控制台窗口之前,计算机将等待您按ENTER键。