tags:

views:

90

answers:

1

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>>;
+9  A: 

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.

dtb
+1 I knew using could do aliasing, but never thought of it aliasing a specific type like this, and the scoping is news as well. Good info!
Jimmy Hoffa