alias

C Sharp Programming · Wikibooks

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From Wikibooks, under CC BY-SA 4.0, as the source states it. This page at Wikibooks.

    alias

    The alias keyword is used to indicate an external alias.

    When you need to use several versions of the same assembly or assemblies with the same full qualified typenames, you need to use the alias and extern keywords to give different alias names for each version.

    Example:

    extern alias AppTools;
    extern alias AppToolsV2;
    

    To use the typenames of each version, you have the operator :: .

    Example:

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

    However, this only says to the compiler that there are several assemblies with typename conflicts. To relate what of each assemblies match's the alias name, you have to tell the compiler on its options apart the source. On dotNet command line, this options would be:

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

    Notice: In order for it to be of use, you need to provide an external assembly to the compiler (e.g. pass /r:EXTALIAS=XXX.dll) and identify the external alias within the code (e.g. extern alias EXTALIAS;)



    C# Keywords
    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
    Special C# Identifiers (Contextual Keywords)
    add alias async await dynamic
    get global nameof partial remove
    set value when where yield
    Contextual Keywords (Used in Queries)
    ascending by descending equals from
    group in into join let
    on orderby select where