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

Some of My Bests

ডাটা স্ট্রাকচার- স্ট্যাক (Stack)

Programming is all about data manipulation. Data structure is way of storing data for further manipulation. ডাটা স্ট্রাকচার আমাদেরকে বিভিন্ন ডাটা সাজিয়ে রাখার ব্যবস্থা করে দেয়। ডাটা সাজিয়ে রাখার অনেক গুলো "তরিকা" আছে। কোনকিছু আমরা কেন সাজিয়ে রাখি? যেন পরে নির্দিষ্ট একটা ডাটা সহজে খুঁজে পেতে পারি। "তরিকা" গুলোর নাম Array, Stack, Queue, Linked List, Tree, Graph. এগুলা শ খানেক ডাটা স্ট্রাকচারের মধ্যে কিছুর নাম, যেগুলো অনেক বেশি ব্যবহার হয়। এই পোস্টটা স্ট্যাক বুঝানোর জন্য। স্ট্যাক খুবই ইন্টেরেস্টিং একটা ডাটা স্ট্রাকচার। অনেক কারনেই এটা ব্যাবহার হয়। আগে স্ট্যাক কনসেপ্টটা নিয়ে আলোচনা করা যাক। স্ট্যাক বলতে বোঝায় একটার উপর একটা সাজায়ে রাখা। বিয়ের বাড়িতে আগে মেলামাইনের গ্লাস দেখা যেত একটার ভেতর আরেকটা ঢুকায়ে লম্বা একটা পাইল তৈরি করে একসাথে ক্যারি করা হচ্ছে। এটা একটা স্ট্যাক। প্রোগ্রামিং এর ভাষায় স্ট্যাক এক্সাক্টলি সেইম জিনিসই। তবে একটু ঘষামাজা আছে। আরেকটা উদাহরণ দেয়া যেতে পারে। বয়ামের ভেতর একটার পর আরেকটা বিস্কিট ঢুকিয়ে রাখা হয়। হ্যা, এইটা পারফেক্ট উদাহরণ হয়েছে। এই...

ডাটা স্ট্রাকচার- কিউ (Queue)

Programming is all about data manipulation. Data structure is way of storing data for further manipulation. ডাটা স্ট্রাকচার আমাদেরকে বিভিন্ন ডাটা সাজিয়ে রাখার ব্যবস্থা করে দেয়। ডাটা সাজিয়ে রাখার অনেক গুলো "তরিকা" আছে। কোনকিছু আমরা কেন সাজিয়ে রাখি? যেন পরে নির্দিষ্ট একটা ডাটা সহজে খুঁজে পেতে পারি। "তরিকা" গুলোর নাম Array, Stack, Queue, Linked List, Tree, Graph. এগুলা শ খানেক ডাটা স্ট্রাকচারের মধ্যে কিছুর নাম, যেগুলো অনেক বেশি ব্যবহার হয়। এই পোস্টটা কিউ বুঝানোর জন্য। কিউ জিনিসটার সাথে আমরা সবাই পরিচিত। জীবনে আমরা সবাই কখনো না কখনো লাইনে দাঁড়ায়ছি। কিউ এর বেসিক ক্যারেক্টারিস্টিকসের সাথে মিলিয়েই প্রোগ্রামিং এ কিউ এর কনসেপ্ট। বাস্তব জীবনে একটা কিউ তে কি হয়? সবাই লাইন ধরে দাঁড়ায় কিছু একটা কারনে। যে সবার আগে দাঁড়ায় সেই সবার আগে কার্জসিদ্ধি করে। সবার পরের জন সবার পরে। স্ট্যাকের ক্ষেত্রে আমরা পড়েছিলাম Last In First Out (LIFO) or First In Last Out (FILO)। কেমন আনফেয়ার শোনায় না? সবার পরে আসবে, আবার সবার আগে চলে যাবে। অ্যাটলিস্ট আমার আনফেয়ার লেগেছিলো যখন স্ট্যাক শিখছিল...

Building a Tic Tac Toe Console Game in C#

When learning a new programming language, a common exercise is to create a classic game, such as Tic Tac Toe. In this post, I'll guide you through creating a simple, console-based Tic Tac Toe game in C#. First, let's start with the challenge we're trying to solve: Tic Tac Toe is a two-player game. We need to handle input from two players and alternate between them. The game is played on a 3x3 grid. We need to keep track of the state of this grid. A player wins by marking three spots in a row, either horizontally, vertically, or diagonally. The game continues until a player has won or all spots on the grid have been marked, in which case the game is a draw. To address these challenges, we need to develop a problem-solving mindset. Let's break down the problem into smaller, manageable pieces and think about how we could solve each one. This process is known as "decomposition" and it's a fundamental skill in programming and problem-solving in general. Step 1:...