Pytanie:
1.
You have a class named Customer and a class named Order. The Customer Class has a 4 property named Orders that contains a list of Order objects. The Order class has a property named OrderDate that contains the date of the Order. You need a LINQ query that returns all of the customers who had at least one order during the year 2005.
[Any, Select, Where, ==, Join, =>]
List<Customer> customersWithOrdersIn2005 =
customers.Where (c. => c.Orders.Any(o => o.OrderDate.Year == 2005)).ToList();
If int? i = 2; which of the following assigns the value 2 to j?
Wybierz wszystkie poprawne:
a) int j = i;
Ta opcja nie jest poprawna, ponieważ i jest typu nullable (int?), a j jest typu int. Wartość i trzeba odpakować przed przypisaniem do j.
b) int j = i ? i : 0;
Ta opcja jest niepoprawna, ponieważ warunek i > i jest zawsze fałszywy, co oznacza, że wartość j zawsze będzie 0.
c) None of those given;
Ta opcja oznacza, że żadna z podanych odpowiedzi nie jest poprawna, co nie jest prawdą.
d) int j = i ?? 0;
Ta opcja jest poprawna. Operator ?? (null-coalescing operator) sprawdza, czy i jest null. Jeśli nie, przypisuje wartość i do j. Jeśli i jest null, przypisuje wartość 0. W naszym przypadku i ma wartość 2, więc j otrzyma wartość 2.
e) int j = (i is null)? 0 : i;
Ta opcja jest poprawna. Operator warunkowy ?: sprawdza, czy i jest null. Jeśli i jest null, przypisuje 0 do j, w przeciwnym razie przypisuje wartość i. W naszym przypadku i ma wartość 2, więc j otrzyma wartość 2.
Poprawne: d i e.
Orki Zkrakowa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.