본문 바로가기

★Dev★/Linq

[Linq] QueryOperator - Where private List cameraList = new List { "Likon", "Canon", "Sony", "Pentax", "Olympus" }; // Where() 확장 메서드 : 조건 검색 // "o"를 포함하고 매개변수의 길이가 5이상인 자료 검색 var cameras = cameraList.Where(p => p.Contains('o') && p.Length >= 5); Response.Write("o를 포함하고 매개변수의 길이가 5이상인 자료 검색 "); foreach (var c in camera) { Response.Write(c + " "); } // 대소문자 구분var cameras = cameraList.Where(p => p.Contains('O') && p.Length >= .. 더보기
[Linq] QueryOperator - OrderBy // OrderBy(), OrderByDescending() : 정렬 출력 List cameraList = new List { "Likon", "Canon", "Sony" }; Response.Write("기본 ======== "); foreach (var camera in cameraList) { Response.Write(camera + " "); } // OrderBy() : Ascending 정렬 -> 오름차순 정렬 Response.Write("오름차순 정렬 ======== "); foreach (var camera in cameraList.OrderBy(n => n)) { Response.Write(camera + " "); } Response.Write("내림차순 정렬 ======== "); .. 더보기
[Linq] QueryOperator - Single //Single() 확장 메서드 : 단일값 반환List cameraList = new List { "Likon", "Canon", "Sony" };List intList = new List { 1, 101, 2, 200 }; string r = "Camera List : "; foreach (string s in cameraList) { if (s == "Likon") { r += s; } } Response.Write(r); Response.Write(""); string camera; //name = names.Single(n => n == "Samsung"); //없으면 에러발생 camera = "Camera : " + cameraList.SingleOrDefault(n => n == "Samsun.. 더보기
[Linq] QueryOperator - Select / SelectMany //Select : 전체 컬렉션값 조회string[] arr = { "abc", "def", "ghi", "jkl" }; var s1 = arr.Select(a => a); foreach (var item in s1) { Response.Write(item + " "); } //SelectMany : 하위 집합 조회 -> char형으로 분리 var s2 = arr.SelectMany(a => a); foreach (var item in s2) { Response.Write(item + " "); } 더보기
[Linq] xml - Load ==== Books.xml ==== 01 LINQ따라하기 IT 02 MVC게시판 IT 03 jQuery게시판 IT // XElement.Parse("..."); XElement countries = XElement.Load(Server.MapPath("Books.xml")); // 방법1 var countriesWithPhNoFormat = from c in countries.Elements() where c.Element("Name") != null && (string)c.Element("Name").Value != "" select c; // 방법2 var countriesWithPhNoFormat2 = from c in countries.Elements() where c.Descendants("Na.. 더보기