0

In the following code snippet:

public static Dictionary<int, string> myDictionary = new Dictionary<int, string>()

the type <int, string> is written twice.

Can it be this be defined in some way to that the type only has to be written once?

So that the code would then look something like that suggested by the following pseudocode:

define myType = <int, string>
public static Dictionary<myType> myDictionary = new Dictionary<myType>()
gnitsuk
  • 31
  • 3
  • 2
    How about `public static Dictionary myDictionary = new()`? – Sweeper May 16 '22 at 10:39
  • You can use `public static Dictionary myDictionary = new();` notation, – McNets May 16 '22 at 10:39
  • 1
    I'm sure this is a duplicate, and I'll leave someone else to find it, but you can do something like `using Bob = System.Collections.Generic.Dictionary;` (i.e. declare an alias) and then in your code `Bob myDictionary = new Bob();`, but I'd recommend against it since that will make your code more difficult to follow. – ProgrammingLlama May 16 '22 at 10:40
  • 1
    `` is not a type, `Dictionary` is. – Klaus Gütter May 16 '22 at 10:40
  • Lightning fast responses as ever! Thanks very much to all for your advice. – gnitsuk May 16 '22 at 10:48

0 Answers0