C# using alias as type parameter in other using alias

前端 未结 5 1248
既然无缘
既然无缘 2021-01-13 01:33

I\'m trying to define a pair of type aliases at the top of my C# program. This is a short example of what I\'m trying to do:

using System;
using System.Colle         


        
5条回答
  •  遥遥无期
    2021-01-13 02:13

    From MSDN's Using alias directives :

    The order in which using-alias-directives are written has no significance, and resolution of the namespace-or-type-name referenced by a using-alias-directive is not affected by the using-alias-directive itself or by other using-directives in the immediately containing compilation unit or namespace body. In other words, the namespace-or-type-name of a using-alias-directive is resolved as if the immediately containing compilation unit or namespace body had no using-directives.

    // emphasis mine

    In your example, the last using-alias-directive results in a compile-time error because it is not affected by the first using-alias-directive.

提交回复
热议问题