TOC

This article is currently in the process of being translated into Bangla (~55% done).

Getting started:

Hello, world!

যদি আপনি কখনও কোনো প্রোগ্রামিং ভাষা শিখে থাকেন তাহলে আপনি অবশ্যই জানেন যে, সবগুলোই শুরু হয় "Hello, World!" এর উদাহরণ দিয়ে। আর তাই এখানেও আমরা সেই ঐতিহ্য ভঙ্গ করি নি। প্রথমেই ভিজ্যুয়াল স্টুডিও অ্যাপটি (পূর্ববর্তী অধ্যায় বর্ণীত) চালু করে File -> New -> Project সিলেক্ট করুন। তারপর প্রজেক্ট ডায়ালগ হতে Console App (.NET framework) বাছাই করুন। এটি মূলত উইন্ডোজের একেবারেই প্রাথমিক পর্যায়ের অ্যাপ্লিকেশন টাইপ, কিন্তু নতুন কোনো ভাষা শেখার জন্য এটি আদর্শ। যখন আপনি এটি সিলেক্ট করে OK বাটনে ক্লিক করবেন তখন ভিজ্যুয়াল স্টুডিও স্বয়ংক্রিয় ভাবে আপনার জন্য একটি নতুন প্রজেক্ট তৈরি করে দিবে যেটির নাম সাধারণত Program.cs দিয়ে শুরু হয়। মূলত এখান থেকেই সকল মজার শুরু এবং আমাদের প্রথম প্রোগ্রামটি দেখতে অনেকটা নিম্নরুপঃ

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
static void Main(string[] args)
{
}
    }
}

আসলে উপরে যেসব লাইন গুলো দেওয়া আছে তা কোনোটিই কোনো কাজে আসবে না, এবং তা দেখে এমনই মনে হওয়ার কথা। আপনি কীবোর্ডের F5 বাটন পুশ করে অ্যাপ টি চালিয়ে দেখতে পারেন। এতে করে ভিজ্যুয়াল স্টুডিও কোডটি কম্পাইল এবং এক্সেকিউট করবে, কিন্তু আপনি দেখবেন এটি তেমন কিছুই করছে না। আপনি শুধু দেখবেন একটা কালো রঙয়ের উইন্ডো লাঞ্চ হয়ে আবার বন্ধ হয়ে যাবে। এর কারণ হচ্ছে আমাদের অ্যাপ্লিকেশান টি এখনও কোনো কিছু করে নি। পরবর্তী অধ্যায় আমরা দেখবো যে উপরিউক্ত লাইন গুলো দিয়ে আসলে কী বুঝাচ্ছে, কিন্তু এখনকার জন্য, আমরা সত্যিই কোনো ফলাফল দেখতে চাচ্ছি। তো, মনে করা যাক আমরা C# সম্পর্কে জানি এবং কিছু লাইন যোগ করি, এতে করে আমরা কিছু আউটপুট দেখতে পাবো। এর জন্য লাস্ট { } সেটে নীচের মতো লাইনগুলো এড করে নিইঃ

Console.WriteLine("Hello, world!");
Console.ReadLine();

The code of your first application should now look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
Console.ReadLine();
}
    }
}

Once again, hit F5 to run it, and you will see the black window actually staying, and even displaying our greeting to the world. Okay, so we added two lines of code, but what to they do? One of the nice things about C# and the .NET framework is the fact that a lot of the code makes sense even to the untrained eye, which this example shows.

The first line uses the Console class to output a line of text, and the second one reads a line of text from the console. Read? Why? Actually this is a bit of a trick, since without it, the application would just end and close the window with the output before anyone could see it.

The ReadLine command tells the application to wait for input from the user, and as you will notice, the console window now allows you to enter text. Press Enter to close it. Congratulations, you have just created your first C# application! Read on in the next chapter for even more information about what's actually going on.