继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

C# 6.0的Dictionary语法

BIG阳
关注TA
已关注
手记 308
粉丝 68
获赞 456

在C# 6.0,当我们使用Dictionary时,我们可以使用新语法,来去简化程序以提高效率。

public Dictionary<string, object> OldToolLocations = new Dictionary<string, object>()
        {
            {"ToolLocation_nbr" ,1},
            {"LocationName", "A2" },
            {"Description", "C4" },
            {"IsActive", true}
        };

        public Dictionary<string, object> NewToolLocations { get; set; } = new Dictionary<string, object>()
        {
            ["ToolLocation_nbr"] = 1,
            ["LocationName"] = "A2",
            ["Description"] = "C4",
            ["IsActive"] = true
        };

 

下面使用ASP.NET MVC项目,举个例子来说明,代码是可行性:

public ActionResult CSharp6DictionaryTest()
        {
            ToolLocationEntity tlc = new ToolLocationEntity();           
            ViewData["OldToolLocations"] = tlc.OldToolLocations;
            ViewData["NewToolLocations"] = tlc.NewToolLocations;
            return View();
        }



这次Insus.NET是使用ViewData来处理,呵呵,方法可多呢,想使用哪种就哪种,开发这些事,想得到的,也就有可以实现得到。

 

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP