简体   繁体   English

在Visual C#2010 Express中编译C#代码

[英]Compiling C# Code in Visual C# 2010 Express

I just have one question regarding C#. 我只有一个关于C#的问题。

I have downloaded Microsoft Visual C# 2010 Express to write the C# code. 我已经下载了Microsoft Visual C#2010 Express来编写C#代码。

Now, I want to compile the code using the same visual C#. 现在,我想使用相同的Visual C#编译代码。 Can I? 我可以吗?

I have searched for a method to compile the code but all of the methods I founded are talking about command line 'cmd'. 我已经搜索了一个编译代码的方法,但我创建的所有方法都在讨论命令行'cmd'。 I tried using it but it gives me that "csc is not recognized as an internal or external command ....." although that the directory I was in is the same as the C# code directory 我尝试使用它,但它给了我“csc不被识别为内部或外部命令.....”虽然我所在的目录与C#代码目录相同

I want to compile and see the results in the output. 我想编译并在输出中查看结果。

This is the original code to compile: 这是要编译的原始代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Project1
{
    class Example1_1
    {
        public static void Main()
        {
            // display “Hello World!” on the screen
            System.Console.WriteLine("Hello World!");
            // display the current date and time
            System.Console.WriteLine("The current date and time is " +
            System.DateTime.Now);
        }
    }
}

and the result of pressing F6 'build' is: 按F6'build'的结果是:

------ Build started: Project: Project1, Configuration: Release x86 ------ ------ Build build:项目:Project1,配置:发布x86 ------
Project1 -> C:\\Users\\Ali Alnufaili\\AppData\\Local\\Temporary Projects\\Project1\\bin\\Release\\Project1.exe ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ========== Project1 - > C:\\ Users \\ Ali Alnufaili \\ AppData \\ Local \\ Temporary Projects \\ Project1 \\ bin \\ Release \\ Project1.exe ==========构建:1成功或最新,0失败,0跳过==========

If you have any suggestion, till me please. 如果您有任何建议,请告诉我。 ^_^ ^ _ ^

Just press this button: 只需按此按钮:

在此输入图像描述

or hit F5 to compile and run your code. 或按F5编译并运行您的代码。

EDIT: 编辑:

So you are running a console application and write some text to the console. 因此,您正在运行控制台应用程序并将一些文本写入控制台。 Maybe your problem is that the console window pops up and closes immediately? 也许你的问题是控制台窗口弹出并立即关闭?

Try adding System.Console.ReadKey(); 尝试添加System.Console.ReadKey(); at the bottom of your Main method. 在Main方法的底部。 Then the console window will stay open until you hit a key. 然后控制台窗口将保持打开状态,直到您按下某个键。

Or go the directory where your compiled program is (looks like it is C:\\Users\\Ali Alnufaili\\AppData\\Local\\Temporary Projects\\Project1\\bin\\Release), open a command prompt (in windows explorer, hold down SHIFT and press the right mouse button and choose Open command prompt here ), and run the executable in the command prompt (just type Project1.exe and hit enter) 或者转到编译程序所在的目录(看起来像是C:\\ Users \\ Ali Alnufaili \\ AppData \\ Local \\ Temporary Projects \\ Project1 \\ bin \\ Release),打开命令提示符(在Windows资源管理器中,按住SHIFT并按鼠标右键并选择打开命令提示符 ,然后在命令提示符下运行可执行文件(只需键入Project1.exe并按Enter键)

If you've created a project in Visual Studio, you should be able to simply use the "build" option from the menus/toolbars. 如果您已在Visual Studio中创建项目,则应该只需使用菜单/工具栏中的“构建”选项即可。

If you've got the default C# key bindings, I believe F6 is a shortcut to start under the debugger. 如果您有默认的C#键绑定,我相信F6是在调试器下启动的快捷方式。

I'm sure you have used some tutorial for the example. 我确定你已经使用了一些教程来举例说明。 Did the tutorial not mention pressing F5 to compile and run the application? 教程没有提到按F5来编译和运行应用程序吗?

Your Build output says your program has compiled successfully, but to start your application, too, you need to press F5 . 您的Build输出表明您的程序已成功编译,但要启动您的应用程序,您需要按F5

Also, currently your program will immediately exit when done. 此外,目前您的程序将在完成后立即退出。 To make it wait, add the following line at the end: 要使其等待,请在结尾添加以下行:

Console.ReadLine();

That will let you see your output and then the program will wait until you press enter. 这将让你看到你的输出,然后程序将等到你按Enter键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM