跳轉到內容

C# 程式設計/關鍵字/別名

來自華夏公益教科書,自由的教科書

alias 關鍵字用於指示一個 外部別名

當您需要使用同一個程式集的多個版本或具有相同完全限定型別的程式集時,您需要使用 aliasextern 關鍵字為每個版本指定不同的別名。

示例

extern alias AppTools;
extern alias AppToolsV2;

要使用每個版本的型別名,您有運算子 :: .

示例

AppTools::MainTool tool_v1 = new AppTools::MainTool();
AppToolsV2::MainTool tool_v2 = new AppToolsV2::MainTool();

但是,這隻會告訴編譯器存在多個具有型別名衝突的程式集。要關聯每個程式集中的哪些匹配別名,您必須在編譯器的選項中指定原始碼的區分方式。在 dotNet 命令列中,這些選項將是

/r:AppTools=AppToolsv100.dll /r:AppToolsV2=AppToolsv200.dll

注意:為了使其有用,您需要向編譯器提供一個外部程式集(例如,傳遞 /r:EXTALIAS=XXX.dll)並在程式碼中標識外部別名(例如 extern alias EXTALIAS;)。



C# 關鍵字
abstract as base bool break
byte case catch char checked
class const continue decimal default
delegate do double else enum
event explicit extern false finally
fixed float for foreach goto
if implicit in int interface
internal is lock long namespace
new null object operator out
override params private protected public
readonly ref return sbyte sealed
short sizeof stackalloc static string
struct switch this throw true
try typeof uint ulong unchecked
unsafe ushort using var virtual
void volatile while
C# 特殊識別符號(上下文關鍵字)
add alias async await dynamic
get global nameof partial remove
set value when where yield
上下文關鍵字(在查詢中使用)
ascending by descending equals from
group in into join let
on orderby select where
華夏公益教科書