Skip to main content

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:

  1. Open Notepad++ and create a new file.
  2. Save the file with a ".cs" extension, indicating that it's a C# source file.
  3. Type the following code:

    
                      
    using System;
    
    class HelloWorld
    {
        static void Main()
        {
            Console.WriteLine("Hello, World!");
        }
    }
    

  4. 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.
  1. Create a new text file named "compile.bat" in the same folder as your C# source file.
  2. Open "compile.bat" in Notepad++ and add the following code:

    
                         
    @echo off
    dotnet build -o output
    

  3. Save and close the file.

  4. Create another new text file named "run.bat" in the same folder as your C# source file.

  5. Open "run.bat" in Notepad++ and add the following code:

    
                         
    @echo off
    dotnet output\HelloWorld.dll
    

  6. 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:


  1. 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!");
        }
    }

  2. 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.
  3. 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.

Conclusion:

Now that you've set up your development environment and created your first C# program, it's time to dive deeper into C# programming. In the next post, we'll be discussing "Understanding data types, variables, and operators," which will introduce you to fundamental programming concepts in C#. Stay tuned for more C# learning!

Comments