°£´ÜÇÑ Linq ¿¹Á¦¿¡ ´ëÇؼ ¾Ë¾Æº¸ÀÚ. Linq ¸Þ¼Òµå´Â IEnumerable¸¦ »ç¿ëÇÏ¿© ±¸ÇöÇÑ´Ù. ÄÝ·º¼Ç¿¡¼ IEnumerable ±¸Çϱâ¹è¿, List, DictionaryÀÇ ¸®ÅÏ°ªÀº IEnumerableÀÌ´Ù.using System;
using System.Collections.Generic; class Program { static void Main(string[] args) { int[] array = { 1, -1, 2, -2, 3 }; IEnumerable<int> intEnumerable = array; List<int> list = new List<int>(); IEnumerable<int> listEnumerable = list; Dictionary<int, int> dic = new Dictionary<int, int> { { 2, 3 }, { 3, 5 }, { 6, 7 } }; //Dictionary´Â IEnumerable<KeyValuePair<TKey, TValue>>·Î ½ÖÀ» ¸¸µç´Ù. IEnumerable<KeyValuePair<int, int>> dicEnumerable = dic; Console.ReadKey(); } } IEnumerable.FirstOrDefault ¸Þ¼ÒµåÁ¶°Ç¿¡ ¸Â´Â ½ÃÄö½ºÀÇ Ã¹¹ø° °ªÀ» ¸®ÅÏÇÑ´Ù. ÇØ´çÇÏ´Â °ªÀÌ ¾ø´Â °æ¿ì ±âº»°ªÀ» ¸®ÅÏÇÑ´Ù.using System;
using System.Linq; class Program { static void Main(string[] args) { int[] numbers = new int[] { 1, 2, 3, 4, 5 }; Console.WriteLine(numbers.FirstOrDefault(c => c > 3)); Console.WriteLine(numbers.FirstOrDefault(c => c > 5)); //±âº»°ª ¸®ÅÏ Console.ReadKey(); } } °á°ú°ª : 4 0 Enumerable.ToDictionary (TSource, TKey) ¸Þ¼µåEnumerableÀ» Dictionary¸¦ ¸¸µç´Ù.using System; using System.Collections.Generic; using System.Linq; class People { public string Name { get; set; } public int Age { get; set; } public override string ToString() { return string.Format("Name = {0}, Age = {1}", Name, Age); } } class Program { static void Main(string[] args) { People[] array = new People[] { new People() { Name = "nana kim", Age = 20 }, new People() { Name = "sena oho", Age = 21 }, new People() { Name = "koko lee", Age = 20 } }; Dictionary<string, People> dic = array.ToDictionary(p => p.Name); foreach (People n in dic.Values) { Console.WriteLine(n); } Console.ReadKey(); } } ÂüÁ¶) http://blog.jhashimoto.net/entry/20120309/1331283458 ¿¹Á¦·Î ¹è¿ì´Â C# http://www.csharpstudy.com/CSharp/CSharp-extension-method2.aspx |