TOC

This article has been localized into isiZulu by the community.

Ukuqala isifundo:

Hello, world!

Uma kuwukuthi uke walufunda ulimi lokukwenza ama-program, kumelwe ukuba uyazi ukuthi zonke izilimi zama-program ziqala ngesibonelo esithi "Hello, world!", futhi singobani thina ukuba sishintshe lolo siko oluhle kangaka? Vula iVisual Studio Community (esikhulume ngayo esahlukweni esidlule), bese ukhetha u-File -> New -> Project. Ebhokisini lama-project, khetha u-Console App (.NET framework). Lolu uhlobo olulula lwe-application yakwaWindows, kodwa luhle kakhulu lapho ufunda ulimi lokubhala ama-program. Ngemva kokuchofoza u-Ok, iVisual Studio uzokuvulela i-project entsha, Kanye nefayela elibhalwe ukuthi Program.cs. Lapho yilapho izinto zenzeka khona, futhi kumelwe kubukeke kanje:

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)
{
}
    }
}

Empeleni, yonke le misho noma imigqa ayenzi lutho, noma kubonakala sengathi ayifezi lutho. Ake uzame uku-runner le application ngokuchofoza u-F5 ku-keyboard yakho. Lokho kuzokwenza ukuba I-Visual Studio yenze i-compile ne-execute yekhodi, kodwa njengoba uzobona, akwenzeli lutho olutheni. Uzomane nje ubone i-window elimnyama livuleka liphinde livaleke futhi. That is because our application doesn't do anything yet. In the next chapter we will go through these lines to see what they are all about, but for now, we really would like to see some results, so let's pretend that we know all about C# and add a couple of lines to get some output. Inside the last set of { }, add these lines:

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

Ikhodi ye-application yakho yokuqala kufanele manje ibukeke kanje:

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();
}
    }
}

Uma usufuna ukuyibona ukuthi isebenza kanjani, phinde uchofoze u-F5, uzobe usubona iwindow elimnyama lingasanyamalali njengasekuqaleni, futhi kuzovela namazwi owabhalile athi Hello, world! Into esiyenzile kube nje ukunezela imigqa emibili yekhodi, kodwa yenzani ngempela? Enye yezinto ezinhle kakhulu ngo-C# ne-.NET framework ukuthi amakhodi amaningi ayazicacela nje ukuthi asho ukuthini ngisho nakumuntu angajwayelene nawo, njengoba lesi sibonelo sibonisa.

Ulayini wokuqala usebenzisa i-Console class ukuze ubhale umusho esifisa ukuthi ubhaleke, bese kuthi umusho wesibili ufunde lowo musho kuyi-console. Uwufunde? Kungani? Empeleni lokhu kuthanda ukuba yinto eyinkimbinkimbi, ngoba ngaphandle kwalo musho wesibili, i-application ingavele iyeke ukusebenza bese iwindow livaleka singasakwazanga ukubona nokuthi belibhaleni.

Amazwi athi ReadLine atshela i-application ukuthi ayilinde lowo oyisebenzisayo ukuba achofoze inkinobho ethile, futhi njengoba uzophawula, i-console window manje iyakuvumela ukuba ubhale okuthile. Chofoza u-Enter ukuze ulivale. Halala, usuyakhile i-application yakho yokuqala ngqa ka-C#! Qhubekela esahlukweni esilandelayo ukuze uthole okwengeziwe mayelana nokuthi kwenzekani ngempela.