Here is an example of a simple C# program that prints the text "Hello, World!" to the console:
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
To create and run a C# program, you need to have the .NET SDK (Software Development Kit) installed on your computer. You can download and install the .NET SDK from the official Microsoft website.
Once you have the .NET SDK installed, you can use a text editor (such as Notepad or Visual Studio Code) to write your C# code. Save the file with a .cs extension, for example, HelloWorld.cs.
To compile the program, open a command prompt or terminal, navigate to the directory where you saved the file, and run the following command:
csc HelloWorld.cs
This will compile the code and create an executable file named HelloWorld.exe.
To run the program, simply type the following command and press Enter:
HelloWorld
This will execute the program and print the text "Hello, World!" to the console.
You can also use a C# Integrated Development Environment (IDE) such as Visual Studio to write, compile, and run C# programs. An IDE provides a more user-friendly interface and additional features such as debugging and code completion.
Comments
Post a Comment