简体   繁体   English

控制器中的C#ASP.NET MVC关联数组

[英]C# ASP.NET MVC Associative array in controller

I have this problem. 我有这个问题。 I have holidays for this and and last year. 我今年和去年都有假期。 You can use last year's holiday in this year. 您可以在今年使用去年的假期。 So lets say for example. 因此,举例来说。 I have 5 days left from 2013 and 20 days for 2014. I need something like in PHP. 我距离2013年还有5天,而2014年还有20天。我需要类似PHP的东西。

$holiday = array();
$holiday['2013'] = 5;
$holiday['2014'] = 20;

So is there any better way to do this in C#? 那么,在C#中还有更好的方法吗?

Use a Dictionary<string,int> 使用Dictionary<string,int>

Look here 这里

I think you are looking for Dictionary . 我认为您正在寻找字典 Something like following. 像下面这样。

Dictionary<int, int> holiday = new Dictionary<int, int>();

holiday[2013] = 5;
holiday[2014] = 20;

Its better if you use int for year instead of string type like in your PHP code. 如果您将int用作年份而不是像PHP代码中那样的字符串类型,那会更好。

A similar - but strongly-typed - collection is a Dictionary. 字典是一个类似但类型严格的集合。 Have a look here . 在这里看看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM