c# – 初始化KeyValuePair数组

栏目: C# · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/4212657/initialising-a-keyvaluepair-array

这似乎是一件简单的事情,但我似乎无法找出正确的语法.我目前有这个:

KeyValuePair<string, string>[] kvpArr = new KeyValuePair<string,string>[];

但是,这似乎有效:

KeyValuePair<string, string>[] kvpArr = new KeyValuePair<string,string>[10];

但我最初不知道数组的大小.我知道我可以使用一系列KVP,我可能会这样做,但我只是想知道如何实现这一目标.

不,你不能这样做 – 因为数组总是有固定的大小.如果您没有指定该尺寸,您希望使用的尺寸是多少?您必须指定大小本身或内容(允许推断大小).例如:

int[] x = new int[10]; // Explicit size
int[] y = new int[] { 1, 2, 3, 4, 5 }; // Implicit size
int[] z = { 1, 2, 3, 4, 5 }; // Implicit size and type

列表与LT; T>绝对是您收藏的朋友,你不知道它的大小.

翻译自:https://stackoverflow.com/questions/4212657/initialising-a-keyvaluepair-array


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Operating System Algorithms

Operating System Algorithms

Nathan Adams、Elisha Chirchir / CreateSpace Independent Publishing Platform / 2017-4-21 / USD 39.15

Operating System Algorithms will walk you through in depth examples of algorithms that you would find in an operating system. Selected algorithms include process and disk scheduling.一起来看看 《Operating System Algorithms》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具