Skip to content

Instantly share code, notes, and snippets.

@musoftware
Last active August 24, 2021 12:05
Show Gist options
  • Save musoftware/889b248224ef1906f1504a178e7cb37d to your computer and use it in GitHub Desktop.
Save musoftware/889b248224ef1906f1504a178e7cb37d to your computer and use it in GitHub Desktop.
make Dict
using System;
using System.Collections.Generic;
namespace test
{
class Program
{
static void Main(string[] args)
{
MakeDict(new int[] { 10, 20, 30 }, new string[] { "B1", "B2", "B3" });
}
static Dictionary<int, string> MakeDict(int[] keys, string[] values)
{
if (keys.Length != values.Length) return null;
var dict = new Dictionary<int, string>();
for (int i = 0; i < keys.Length; i++)
{
dict.Add(keys[i], values[i]);
Console.WriteLine("{0} -> {1}", keys[i], values[i]);
}
return dict;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment