Skip to content

Instantly share code, notes, and snippets.

@olecksamdr
Created October 20, 2016 00:09
Show Gist options
  • Save olecksamdr/094430afc0c8a1f466334d92e5df5378 to your computer and use it in GitHub Desktop.
Save olecksamdr/094430afc0c8a1f466334d92e5df5378 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
// class MyMap<TKey, TValue>: IEnumerable
// {
// private List<KeyValuePair<TKey, TValue>> items = new List<KeyValuePair<TKey, TValue>>();
// public MyMap()
// {
// }
// public void Add(TKey key, TValue value)
// {
// KeyValuePair<TKey, TValue> pair = new KeyValuePair<TKey, TValue>(key, value);
// items.Add(pair);
// }
// public TValue this[TKey key]
// {
// get
// {
// foreach (KeyValuePair<TKey, TValue> item in items)
// {
// if (item.Key.Equals(key)) return item.Value;
// else
// {
// throw new Exception("item with key: " + key +", not found");
// return default (TValue);
// }
// }
// }
// }
// class MyMap: IEnumerable
// {
// private List<KeyValuePair<char, double>> items = new List<KeyValuePair<char, double>>();
// public MyMap()
// {
// }
// public void Add(char key, double value)
// {
// KeyValuePair<char, double> pair = new KeyValuePair<char, double>(key, value);
// items.Add(pair);
// }
// public double this[char key]
// {
// get
// {
// foreach (KeyValuePair<char, double> item in items)
// {
// if (item.Key == key) return item.Value;
// else
// {
// //throw new Exception("item with key: " + key +", not found");
// return 0;
// }
// return 0;
// }
// }
// }
// // for foreach
// public IEnumerator GetEnumerator()
// {
// foreach (KeyValuePair<char, double> item in items)
// {
// yield return item;
// }
// }
// public KeyValuePair<char, double> First()
// {
// return items[0];
// }
// }
class testDictionary {
static void Main() {
Dictionary<string, double> d = new Dictionary<string, double>();
d.Add("first", 0.1);
d.Add("second", 0.2);
d.Add("third", 0.3);
Console.WriteLine(d.First().Value);
Console.WriteLine();
// foreach(KeyValuePair<string, double> item in d)
// {
// Console.WriteLine(item.Value);
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment