DEV Community

Cover image for 1. Top-level statements
MustafaSamedYeyin
MustafaSamedYeyin

Posted on

2 1

1. Top-level statements

Öğreneceklerimiz : C# da To-Level-Statement nedir bunu öğreneceğiz.

Gereksinimler :
dotnet sdk
vs code (c# eklentisiyle)

İstediğniz bir boş bir klasöre locate olup, cmd'yi açıp aşağıdaki komutları sırasıyla çalıştıralım.

dotnet new console -o YourConsoleAppName
Enter fullscreen mode Exit fullscreen mode
cd YourConsoleAppName
Enter fullscreen mode Exit fullscreen mode
code .
Enter fullscreen mode Exit fullscreen mode

Ve Program.cs yi açalım içersinde şu yazılı olmalıdr :

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
Enter fullscreen mode Exit fullscreen mode

Gördüğünüz üzere ne bir namespace ne bir class ne de Main metot var.

Aslında varlar :)

Otomotik olarak namespace, class ve Main metot ekleniyor Program.cs ye ve bu özelliğe Top-level-statements deniyor.

Örneğin :

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Enter fullscreen mode Exit fullscreen mode

yukarıdaki namespace'ler otomotiktan ekleniyor. Kaynak

Sınırlarmalar :

  1. Sadece bir tane top-level file olabilir.
  2. Top-level file namespace ve class'lar içerebilirler ama ama bu namespace ve class'lar top-level statement'lardan sonra gelebilir. Örneğin (bakiniz) :
// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");
namespace NameSpaceIsmi
{
    class SinifIsmi
    {
        //write to Console
        static void Yaz(string yazilacak)
        {
            Console.WriteLine(yazilacak);
        }
    }

}
Enter fullscreen mode Exit fullscreen mode

Async metotları nasıl kullanırız ?

Async metodun direkt önüne await keyword'ü yazarak async metotları kullabilir (bakiniz) :

Console.Write("Hello ");
await Task.Delay(5000);
Console.WriteLine("World!");
Enter fullscreen mode Exit fullscreen mode

Gizlice yazılan main metot tablosu : için tıklayınız

ayrıca top-level-statement'lar hakkında güzel bir yazı

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more