3

Recently I discovered the 'using type alias' directive in C#, so I wrote the following code, just for fun.

namespace ConsoleApplication1
{
    using Row = List<string>;
    using Table = List<Row>;
    using DataBase = Dictionary<string, Table>;

    static class Program
    {
        public static void Main()
        {
            var d = new DataBase();

            Console.Read();
        }
    }
}

but when I try to compile, I get 2 errors: The type or namespace name 'XXX' could not be found. replacing XXX by 'Row' and 'Table'.

Does anyone know why it and how to solve it? (without do using Table = List<List<string>>;)

leandromoh
  • 139
  • 6
  • Not a dupe. According to the answers in the question lined as a duplicate, this should be possible. – Bart van Nierop May 15 '16 at 19:53
  • It is a dupe,but I'm pretty sure you have to fully qualify the namespace to the closed generic type in order for this to work. As a personal preference,I find this to be smelly. You are forced to specify this every time on every page and for someone not familiar with your code, it could be something that slows down immediate comprehension. I like terse code, but sometimes you should just spell it out. – Hardrada May 15 '16 at 20:03
  • @Hardrada using Table = List; also not work =/ – leandromoh May 15 '16 at 20:07
  • Fully qualify everything, including List using Table = System.Collections.Generic.List – Hardrada May 15 '16 at 20:09
  • @BartvanNierop sorry i dont understand. my problem isnt with generics. it's about cascading aliases – leandromoh May 15 '16 at 20:09
  • @Hardrada i tried using Row = System.Collections.Generic.List; using Table = System.Collections.Generic.List; but without sucess – leandromoh May 15 '16 at 20:11
  • So, I totally missed what you meant by cascading. No, I don't think you can do this like you are attempting. You need to do something like this instead. using DataBase = System.Collections.Generic.Dictionary>> using Row =System.Collections.Generic.List using Table = System.Collections.Generic.List> I know it's not self cascading like you want, but it will compile. – Hardrada May 15 '16 at 20:20
  • @Hardrada using Row = List; using Table = List>; using DataBase = Dictionary>>;. it also compile. the trouble is the cascading (using another alias in the definition of an alias).. that sould let the code much clear – leandromoh May 15 '16 at 20:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112071/discussion-between-hardrada-and-leandromoh). – Hardrada May 16 '16 at 15:33

0 Answers0