티스토리 뷰

.NET/C#

LINQ QUIZ

POWERUMC 2007. 11. 5. 00:44
LINQ QUIZ
 
간단한 퀴즈를 풀면서 LINQ 에 대한 지식을 테스트 합니다.
모든 샘플은 다음과 같은 네임스페이스가 선언되어 있습니다.
 
using System;
using System.Linq;
using System.Data.Linq;
using System.Xml.Linq;
using System.Collections;
 
그리고 다음과 같은 배열이 선언되어 있습니다.
 
string[] colors = { "green", "brown", "blue", "red" };
 
 
 
자!! 그럼 이제 도전해 보십시오.
 
 
Q1. 다음 표현의 결과는 무엇입니까?
 
colors.Max (c => c.Length)
 
(A) 5
(B) green
(C) brown
(D) Compile-time error
(E) Exception thrown
 
 
Q2. 다음 표현의 결과는 무엇입니까?
 
colors.OrderBy (c => c.Length).Single()
 
(A) 3
(B) red
(C) Compile-time error
(D) Exception thrown
 
 
Q3. 주어진 쿼리식을 보고 답하세요.:
 
var query =
 from c in colors
 where c.Length > 3
 orderby c.Length
 select c;
 
query 변수의 type 은 무엇입니까?
 
(A) int
(B) string
(C) IEnumerable<int>
(D) IEnumerable<string>
(E) IQueryable<int>
(F) IQueryable<string>
 
 
Q4. 다음의 출력 결과는 무엇입니까?
 
var query =
 from c in colors
 where c.Length == colors.Max (c => c.Length)
 select c;
 
foreach (var element in query)
Console.WriteLine (element);
 
colors 배열의 값은 { "green", "brown", "blue", "red" } 입니다.
 
(A) green followed by brown
(B) 5 followed by 5
(C) Compile-time error
(D) Exception is thrown
 
 
Q5. 위의 예제에서 Subquery 는 최대 몇번 실행합니까?
 
(A) 한번
(B) 두번
(C) 세번
(D) 네번
 
 
Q6. 다음 코드의 출력 결과는 무엇입니까?
 
var list = new List<string> (colors);
IEnumerable<string> query = list.Where (c => c.Length == 3);
list.Remove ("red");
 
Console.WriteLine (query.Count());
 
(A) 0
(B) 1
(C) 2
(D) Exception thrown
 
 
Q7. 다음 코드의 출력 결과는 무엇입니까?
 
string[ ] colors = { "green", "brown", "blue", "red" };
 
var query = colors.Where (c => c.Contains ("e"));
query     = query.Where (c => c.Contains ("n"));
 
Console.WriteLine (query.Count());
 
 
(A) 1
(B) 2
(C) 3
(D) 4
 
 
Q8. 다음 코드의 출력 결과는 무엇입니까?
 
string s = "e";
var query = colors.Where (c => c.Contains (s));
 
s         = "n"
query     = query.Where (c => c.Contains (s));
 
Console.WriteLine (query.Count());
 
(A) 1
(B) 2
(C) 3
(D) 4
 
 
Q9. 다음의 쿼리에서, 컴파일러는 쿼리 문법을 어떻게 해석합니까?
 
from c in colors
let middle = c.Substring (1, c.Length - 2)
where middle.Contains ("e")
select middle;
 
(A)  Enumerable.Let을 호출하는 것으로 번역이 된다.
(B)  where, select 구문에서 middle은 c.Substring (1, c.Length - 1)으로 확장된다.
(C) 임시로 익명 타입으로 해석한다.
 
 
Q10. 컴파일러가 여러 생성자를 포함하여 쿼리를 번역하려면…?
 
(A) Multiple Selects
(B) SelectMany
(C) Join
 
 
Q11. 다음 보기 중, LINQ 에서 같이 사용할 수 있는 JOIN 절을 고르시오(복수선택 가능)
 
I.    Inner joins
II.   Left outer joins
III. Full outer joins
IV. Non-equi inner joins
V.   Non-equi outer joins
 
 
Q12. LINQ 의 JOIN 절은 어떤 SQL 구문의 JOIN 을 사용할 수 있습니까?(복수선택가능)
 
I.    Inner joins
II.   Left outer joins
III. Full outer joins
IV. Non-equi inner joins
V.   Non-equi outer joins
 
 
Q13. LINQ to SQL 쿼리는 자신의 로컬 메서드를 호출할 수 있습니까?
 
A. Where 절에서만
B. In the final projection only
C. 쿼리의 어떤곳에서도 가능하다
D. 불가능하다
 
 
Q14. In LINQ to SQL, to request that an entity’s association properties be populated along with the entity (in a single round trip), you would:
 
(A) set DelayLoaded to false in the Association attribute
(B) set EagerLoad to true in the Association attribute
(C) use a DataLoadOptions object, and call AssociateWith
(D) use a DataLoadOptions object, and call LoadWith
 
 
Q15. 다음 코드의 출력 결과는 무엇입니까?
 
var city = new XElement ("city", "Seattle");
 
var customer1 = new XElement ("customer", city);
var customer2 = new XElement ("customer", city);
 
city.SetValue ("London");
Console.WriteLine (customer2.Element ("city").Value);
 
(A) Seattle
(B) London
(C) An exception is thrown
 
 
Q16. 다음 코드에서 element 이름 안의 네임스페이스는 무엇입나까?
 
XNamespace ns = "http://albahari.com/linqquiz";
 
var x =
 new XElement (ns + "customer",
    new XElement ("name", "Bloggs")
);
 
(A) "" (empty string)
(B) "http://albahari.com/linqquiz"
(C) "name"
 
 
Q17. XElement 또는 XDocument 클래스를 사용하여 파일로 XML 을 저장할 때, XML 선언문은 출력파일에 포함이 된다.
 
(A) 항상 포함된다.
(B) 전혀 포함되지 않는다.
(C) XDeclaration 객체를 사용할 경우에만
 
 
 
모든 문제를 푸셨나요? 의외로 긴가민가 한 부분이 많지요? ㅋ
그럼 채점에 들어가겠습니다.
해설까지 번역하려고 하였으나, 짧은 문장력으로 너무 힘드네요~
아래의 주소에 자세한 설명이 나와있으니 한번씩 둘러보시기 바랍니다^^
( Q14 번 번역 가능하신 분 구합니다 ㅡㅡㅋ )
 
 
 
답안
 
Q1. A
Q2. D
Q3. D
Q4. C
Q5. D
Q6. A
Q7. A
Q8. B
Q9. C
Q10. B
Q11. I and IV
      II and V
Q12. I
      II
Q13. B
Q14. D
Q15. A
Q16. A
Q17. A

TAG
댓글
댓글쓰기 폼
공지사항
Total
2,841,738
Today
3
Yesterday
47
«   2023/06   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
글 보관함