Abridged Declaration of Long-Term Collection Types

I looked through many C # generic code examples and did not forget to see the syntax trick of the declaration, which created an alternative abbreviated type for a long generic dictionary type. Mixing C # and C ++ was something like:

typedef MyIndex as Dictionary< MyKey, MyClass>;

This allowed the use of the following:

class Foo
{
    MyIndex _classCache = new MyIndex();
}

Can someone remind me which C # lanaguage feature supports this?

+3
source share
3 answers

This is another directive form used to define an alias.

using MyClass = System.Collections.Generic.Dictionary<string, int>;

namespace MyClassExample
{
    class Program
    {
        static void Main(string[] args)
        {
            var instanceOfDictionaryStringInt = new MyClass();
        }
    }
}
+9
source
using MyIndex = Dictionary<MyKey, MyClass>;
+4
source

Here is an example of how it is made

using Test = System.Collections.Generic.Dictionary<int, string>;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Test myDictionary = new Test();
            myDictionary.Add(1, "One");
        }

    }
}
+2
source

Source: https://habr.com/ru/post/1763318/


All Articles