Chapter 1.2: Introduction to C# and the .NET Framework: Setting up the Development Environment for C# with Notepad++
Introduction
In the previous post, we covered the fundamentals of C# and the .NET framework. Now, we'll set up a lightweight development environment for C# programming using Notepad++ as our code editor, the .NET Core SDK for compilation and execution, and batch files to streamline the process.
Setting Up the Development Environment:
Follow the steps mentioned in the previous post to set up a C# development environment using Notepad++ and the .NET Core SDK.
Creating Your First C# Program:
- Open Notepad++ and create a new file.
- Save the file with a ".cs" extension, indicating that it's a C# source file.
-
Type the following code:
using System; class HelloWorld { static void Main() { Console.WriteLine("Hello, World!"); } }
- Save the file as "HelloWorld.cs" or another filename of your choice.
Creating Batch Files for Compilation and Execution:
To make the process of compiling and running C# programs more convenient, we'll create two batch files, one for compilation and another for execution.
- Create a new text file named "compile.bat" in the same folder as your C# source file.
-
Open "compile.bat" in Notepad++ and add the following code:
@echo off dotnet build -o output
-
Save and close the file.
-
Create another new text file named "run.bat" in the same folder as your C# source file.
-
Open "run.bat" in Notepad++ and add the following code:
@echo off dotnet output\HelloWorld.dll
-
Save and close the file.
Now, you have two batch files that will simplify the process of compiling and executing your C# programs.
Compiling and Running the C# Program using Batch Files:
-
Make sure your "HelloWorld.cs" file is saved in the same folder as the batch files. The contents of "HelloWorld.cs" should look like this:
using System; class HelloWorld { static void Main() { Console.WriteLine("Hello, World!"); } }
- Double-click "compile.bat" to compile the C# program. If the compilation is successful, an executable file (HelloWorld.dll or HelloWorld.exe on Windows) will be created in the "output" folder.
- Double-click "run.bat" to run the compiled program. You should see the output "Hello, World!" in the terminal.
Double-click "compile.bat" to compile the C# program. If the compilation is successful, an executable file (HelloWorld.dll or HelloWorld.exe on Windows) will be created in the "output" folder.
Double-click "run.bat" to run the compiled program. You should see the output "Hello, World!" in the terminal.
Comments
Post a Comment