Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Thread http://forum.unity3d.com/threads/119735-Finding-a-similar-key-in-a-Dictionary]
- // Copyright NPSF3000 2012. ALL RIGHTS RESERVED. NO WARRANTY GIVEN.
- // ATTRIBUTION REQUIRED FOR ALL NON-PERSONAL APPLICATIONS
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Sorted_List_Search
- {
- class Program
- {
- static void Main(string[] args)
- {
- var dates = new SortedList<int, string>
- {
- {1,"r"},
- {5,"g"},
- {9,"b"},
- {10,"x"},
- {15,"y"},
- };
- Console.WriteLine("Enter a positive integer and press enter.");
- Console.WriteLine();
- while (true)
- {
- var input = Console.ReadLine();
- int key;
- if (int.TryParse(input, out key))
- Console.WriteLine(dates.Select(x => x).Where(x => x.Key <= key).OrderByDescending(x => x.Key).First());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement