nan
nan

Reputation: 20296

Using alias with 'using'

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.List
                    <System.Collections.Generic.Dictionary<string, string>>;

Error:

using System;
using System.Collections.Generic;

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

Upvotes: 1

Views: 379

Answers (1)

dtb
dtb

Reputation: 217313

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.

Upvotes: 9

Related Questions