开发者

Using alias with 'using'

开发者 https://www.devze.com 2023-01-16 12:51 出处:网络
I would like to define my own alias for complex type. I\'m curious why the compiler does not recognize already imported types. For example:

I would like to define my own alias for complex type. I'm curious why the compiler does not recognize already imported types. For example:

Works:

using System;
using System.Collections.Generic;

using myCollection = System.Collections.Generic.L开发者_C百科ist
                    <System.Collections.Generic.Dictionary<string, string>>;

Error:

using System;
using System.Collections.Generic;

using myCollection = List<Dictionary<string, string>>;


Try this:

using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    using myCollection = List<Dictionary<string, string>>;
}

using directives can't refer to types imported in the same scope. The above example works, because the last using directive refers only to types imported in an outer scope.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号