C #6.0 Dictionary syntax,

Source: Internet
Author: User

C #6.0 Dictionary syntax,

In C #6.0, when we use Dictionary, we can use the new syntax to simplify the program to improve efficiency.

 

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 };Source Code

 

The following uses the ASP. net mvc project. For example, the Code is feasible:

 

Public ActionResult CSharp6DictionaryTest () {ToolLocationEntity tlc = new ToolLocationEntity (); ViewData ["OldToolLocations"] = tlc. oldToolLocations; ViewData ["NewToolLocations"] = tlc. newToolLocations; return View ();}Source Code

 

Insus. NET has also written several examples in its blog. It is a one-time transmission of multiple models to the MVC view, as shown in

Using ViewModel to implement multiple models to the view http://www.cnblogs.com/insus/p/5594134.html

Http://www.cnblogs.com/insus/p/5595811.html using ExpandoObject for transferring multiple models to a view

Http://www.cnblogs.com/insus/p/5602540.html for transferring multiple models to a view using Tuple


This time, Insus. NET uses ViewData for processing. Ha ha, there are many methods. Which one can be used? You can achieve what you want to develop these things.


The following implementation View:

 

Effect:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.