Aracılığıyla paylaş


using (C# başvurusu)

Anahtar sözcüğün using iki ana kullanım alanı vardır:

  • deyimiusing sonunda bir nesnenin atıldığı bir kapsam tanımlar:
    string filePath = "example.txt";
    string textToWrite = "Hello, this is a test message!";
    
    // Use the using statement to ensure the StreamWriter is properly disposed of
    using (StreamWriter writer = new StreamWriter(filePath))
    {
        writer.WriteLine(textToWrite);
    }
    
  • yönergesi using bir ad alanı için bir diğer ad oluşturur veya diğer ad alanları içinde tanımlanan türleri içeri aktarır:
    using System;
    using System.IO;
    

Ayrıca bkz.