ZH TW CSharp Keyword global - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C#: global

使用手冊C# · 實用指南

global:: 限定詞從根命名空間開始搜尋;全域 using 將名稱匯入到所有專案檔案。

簡單範例 (Example.cs)

請將此範例另存為 Example.cs,並與本頁其他範例分開執行。

Example.cs:

// PROJECT-EXAMPLE
global::System.Console.WriteLine("Root namespace");

結果:

Root namespace

句法

global::System.Console / global using Namespace;

例1:基本形式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        global::System.Console.WriteLine("Root namespace");
    }
}

例2:另一種實用形式

global using System;
public static class Program { public static void Main() { Console.WriteLine("Shared import"); } }

官方來源:Microsoft學習。