キーと値が連続で並ぶ配列から、キー、値のペアを列挙したい
キーと値が連続で並ぶ配列から、キー、値のペアを列挙したいとき、下記のように書いた。
他に良い方法があるかも。
pair.cs
var hoges = new string[] { "key1", "value1", "key2", "value2", "key3", "value", };
var numOfPair = hoges.Count() / 2;
foreach (var pair in Enumerable.Range(0, numOfPair)
.Select(i => new { Key = hoges[i * 2],
Value = hoges[i * 2 + 1], }))
{
// pair.Key ...
// pair.Value ...
}
Author And Source
この問題について(キーと値が連続で並ぶ配列から、キー、値のペアを列挙したい), 我々は、より多くの情報をここで見つけました https://qiita.com/SheepCloud/items/509715614150bb3e53f8著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .