using System.Collections;
using System.Collections.Generic;
namespace ConsoleApplication8
static Dictionary<object, object> map = new Dictionary<object, object>();
public static void Main()
var dateTime = DateTime.UtcNow;
for (int i = 0; i < 100000; i++)
var sentence = Random(5);
if (!map.ContainsKey(sentence))
map.Add(sentence, (Action)Do);
var y = ((Action) map[sentence]);
if (Equals(y, bar)) continue;
Console.WriteLine((DateTime.UtcNow - dateTime).TotalMilliseconds + " ms");
static readonly string[] Words = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" };
public static string Random(int words)
return string.Join(" ", Randomize.Integers(0, Words.Length - 1, words).Select((wordIndex, i) =>
var c = ((ICollection) map);
if (c.Count > 5) map.Remove("lorem");
public static class Randomize
static Random Random = new Random();
public static int Integer(int from, int to)
return Random.Next(from, to);
public static int[] Integers(int from, int to, int count, bool unique = true)
if (unique && to - from + 1 <= count) unique = false;
var set = new HashSet<int>();
while (set.Count != count)
set.Add(Integer(from, to));
return Enumerable.Repeat(1, count).Select(_ => Integer(from, to)).ToArray();