简体   繁体   中英

Compiling C# Code in Visual C# 2010 Express

I just have one question regarding C#.

I have downloaded Microsoft Visual C# 2010 Express to write the C# code.

Now, I want to compile the code using the same 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'. 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

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:

------ Build started: Project: Project1, Configuration: Release 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 ==========

If you have any suggestion, till me please. ^_^

Just press this button:

在此输入图像描述

or hit F5 to compile and run your code.

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(); at the bottom of your Main method. 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)

If you've created a project in Visual Studio, you should be able to simply use the "build" option from the menus/toolbars.

If you've got the default C# key bindings, I believe F6 is a shortcut to start under the debugger.

I'm sure you have used some tutorial for the example. Did the tutorial not mention pressing F5 to compile and run the application?

Your Build output says your program has compiled successfully, but to start your application, too, you need to press 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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