Skip to content
Rain Hu's Workspace
Go back

[C#] Namespace Alias 命名空間別名

Rain Hu

1. 命名空間別名

using System;
using WinForms = System.Windows.Forms;
using WebForms = System.Web.UI.WebControls;

class Program
{
    public static void Main()
    {
        Console.WriteLine(typeof(WinForms.Button));
        Console.WriteLine(typeof(WebForms.Button));
    }
}

2. 命名空間別名限定字符

public static void Main()
{
    Console.WriteLine(typeof(WinForms::Button));
    Console.WriteLine(typeof(WebForms::Button));
}

3. 全局命名空間別名

global using global::System.DateTime;

4. 外部別名

extern alias JsonNet;
extern alias JsonNetAlternative;

using JsonNet::Newtonsoft.Json.Linq;
using AltJObject = JsonNetAlternative::Newtonsoft.Json.Linq.JObject;

JObject obj = new JObject();       
AltJObject alt = new AltJObject(); 

Share this post on:

Previous
[Algo] 3-0. Sorting
Next
[C#] Property getter/setter access separate 訪問權限分離