Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

1.3 Σύνταξη κώδικα στην γλώσσα C#

Σύνταξη C#
Στο προηγούμενο κεφάλαιο, δημιουργήσαμε ένα αρχείο C# με το όνομα Program.cs και χρησιμοποιήσαμε τον παρακάτω κώδικα για να εκτυπώσουμε το “Hello World” στην οθόνη:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
namespace MyConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
}
}
}
using System; namespace MyConsoleApp { class Program { static void Main(string[] args) { Console.WriteLine("Hello, world!"); } } }
using System;

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

Ας αναλύσουμε τη σύνταξη αυτού του κώδικα:

  • Η γραμμή using System; δηλώνει ότι θα χρησιμοποιήσουμε το namespace System, το οποίο περιέχει τις βασικές κλάσεις και τις δομές δεδομένων της C#.
  • Ο ορισμός namespace MyConsoleApp δηλώνει ένα namespace με το όνομα MyConsoleApp. Ένα namespace είναι ένας τρόπος οργάνωσης του κώδικα και της λειτουργικότητας σε λογικές οντότητες.
  • Η δήλωση class Program δημιουργεί μια κλάση με το όνομα Program. Οι κλάσεις είναι οι βασικές μονάδες οργάνωσης του κώδικα στην C#.
  • Η μέθοδος static void Main(string[] args) είναι η κύρια μέθοδος που εκτελείται όταν ξεκινά το πρόγραμμα. Η μέθοδος Main είναι η είσοδος του προγράμματος και από εκεί ξεκινά η εκτέλεση του κώδικα.
  • Η εντολή Console.WriteLine("Hello, world!"); χρησιμοποιείται για να εκτυπώσει το μήνυμα “Hello, world!” στην κεντρική οθόνη. Η Console.WriteLine είναι μια μέθοδος της κλάσης Console που χρησιμοποιείται για την εκτύπωση ενός μηνύματος στην κονσόλα.

Αυτή είναι μια απλή παρουσίαση της σύνταξης C# που χρησιμοποιήσαμε για το παράδειγμα “Hello, world!”. Στα επόμενα κεφάλαια θα εξετάσουμε λεπτομερέστερα τα διάφορα στοιχεία της σύνταξης C# και θα μάθουμε περισσότερα για την ανάπτυξη εφαρμογών σε C#.

21 Αυγούστου, 2023
top
error: Content is protected !!
Μετάβαση σε γραμμή εργαλείων