有没有办法简化字段初始化?

Rom*_*man 0 .net c# .net-core

所以我想知道我是否可以以某种方式简化它,因为它在屏幕上占用了大量空间:

private Dictionary<string, Dictionary<string, List<double>>> storage = new Dictionary<string, Dictionary<string, List<double>>>();
Run Code Online (Sandbox Code Playgroud)

Fur*_*bay 7

您可以使用别名.

using System;
// and others
using MyDict = System.Collections.Generic.Dictionary<string, System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<double>>>;

namespace ConsoleApp1
{
    public class Program
    {
        public static void Main()
        {
            var a = new MyDict();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

或者你可以这样做:

using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    using MyDict = Dictionary<string, Dictionary<string, List<double>>>;

    public class Program
    {
        public static void Main()
        {
            var a = new MyDict();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)