Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Hash-from-two-arrays/C-sharp/hash-from-two-arrays-1.cs
Normal file
17
Task/Hash-from-two-arrays/C-sharp/hash-from-two-arrays-1.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
static class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
System.Collections.Hashtable h = new System.Collections.Hashtable();
|
||||
|
||||
string[] keys = { "foo", "bar", "val" };
|
||||
string[] values = { "little", "miss", "muffet" };
|
||||
|
||||
System.Diagnostics.Trace.Assert(keys.Length == values.Length, "Arrays are not same length.");
|
||||
|
||||
for (int i = 0; i < keys.Length; i++)
|
||||
{
|
||||
h.Add(keys[i], values[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
h[keys[i]] = values[i];
|
||||
14
Task/Hash-from-two-arrays/C-sharp/hash-from-two-arrays-3.cs
Normal file
14
Task/Hash-from-two-arrays/C-sharp/hash-from-two-arrays-3.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System.Linq;
|
||||
|
||||
static class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
string[] keys = { "foo", "bar", "val" };
|
||||
string[] values = { "little", "miss", "muffet" };
|
||||
|
||||
var h = keys
|
||||
.Zip(values, (k, v) => (k, v))
|
||||
.ToDictionary(keySelector: kv => kv.k, elementSelector: kv => kv.v);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue