Basics (5.papers)

1

How to produce a sequence of the uppercase and lowercase versions of each word in the original array? Ex: string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };

var lowNums =from n in numbers where n < 5 select digits[n];

var lowNums=from n in numbers where n<5 select digits[numbers]

var lowNums=from n in numbers where n<5 select digits[n-1]

All of the above

Show Answer

2

How to produce a sequence of strings representing the text version of a sequence of ints? Ex: int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}

var textNums =from n in numbers select strings[n];

var textNums =from n in numbers select new{strings[n]};

var textNums =from n in numbers select new{n[strings]}

All of the above

Show Answer

3

How to produce a sequence of the uppercase and lowercase versions of each word in the original array? Ex: string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };

var upperLowerWords = from w in words select new { Upper = w.ToUpper(), Lower = w.ToLower() };

var upperLowerWords = from w in words select new { Upper = ToUpper(), Lower=ToLower() };

var upperLowerWords = words.ToUpper().ToLower();

both a and c

Show Answer

4

How to produce a sequence containing text representations of digits and whether their length is even or odd? Ex: int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

var digitOddEvens =from n in numbers select new { Digit = strings[n], Even = (n % 2 == 0) };

var digitOddEvens =from n in numbers select new { Digit = n[strings], Even = (n % 4 == 0) };

var digitOddEvens =numbers.select new { Digit = n[strings], Even = (n % 4 == 0) };

None of the above

Show Answer

5

How to produce a sequence containing some properties of Products, including UnitPrice which is renamed to Price in the resulting type?

var productInfos =from p in products select new { p.ProductName, p.Category, Price = p.UnitPrice };

Let Price; var productInfos =from p in products select new { p.ProductName, p.Category, Price = p.UnitPrice };

var productInfos=products.select new{p. ProductName, p.Category, Price = p.UnitPrice };

both a and c

Show Answer

6

How to make a query that returns all pairs of numbers from both arrays such that the number from numbersA is less than the number from numbersB? Ex: int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 }; int[] numbersB = { 1, 3, 5, 7, 8 };

var pairs =from a in numbersA from b in numbersB where a < b select new { a, b };

var pairs =from a in numbersA inner join from b in numbersB where a < b select { a, b };

var pairs =from a in numbersA join from b in numbersB where a < b select { a, b };

Both b and c

Show Answer

7

How to select all orders where the order total is less than 500.00?

var orders =from c in customers where c.Total < 500.00M select new { c.CustomerID, o.OrderID, o.Total };

var orders=customers.where(t=>t.Total<500.00M) select new{c.CustomerID,o.OrderID,o.Total};

var orders=customers.where(t=>t.Toal<500.00M);

both a and c

Show Answer

8

How to select all orders where the order was made in 1998?

var orders =from c in customers from o in c.Orders where o.OrderDate >= new DateTime(1998, 1, 1) select new { c.CustomerID, o.OrderID, o.OrderDate };

var orders =from c in customers from o in c.Orders where o.OrderDate >= new DateTime(1, 1, 1998) select new { c.CustomerID, o.OrderID, o.OrderDate };

both a and b

none of the above

Show Answer

9

How to determine if any of the words in the array contain the substring 'ei'? Ex: string[] words = { "believe", "relief", "receipt", "field" };

bool iAfterE = words.Any(w => w.Contains("ei"));

string iAfterE=words.Any(w=>w.Contains(“ei”));

int iAfterE=words.Any(w=>w.Exists(“ei”));

All of the above

Show Answer

10

How to determine whether an array contains only odd numbers? Ex: int[] numbers = { 1, 11, 3, 19, 41, 65, 19 };

bool onlyOdd = numbers.All(n => n % 2 == 1);

bool onlyOdd = numbers.Any(n => n % 2 == 1);

bool onlyOdd = numbers.At(n => n % 2 == 1);

none of the above

Show Answer

11

How to return a grouped a list of products only for categories that have all of their products in stock?

var productGroups =from p in products group p by p.Category into g where g.All(p => p.UnitsInStock > 0) select new { Category = g.Key, Products = g };

var productGroups =from p in products group p by p.Category into g where g.Any(p => p.UnitsInStock > 0) select new { Category = g.Key, Products = g };

var productGroups =from p in products group p by Category into g where g.All(p => p.UnitsInStock > 0) select new { Category = g.Key, Products = g };

All of the above

Show Answer

12

How where to find all elements of an array less than 5? EX: int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

var lowNums = from n in numbers where n < 5 select n;

varlowNums=n.where(t=>t<5)

both a and b

none of the above

Show Answer

13

How to find all customers in Washington?

var waCustomers = from c in customers where c.Region == "WA" select c

var waCustomers=customers.where(t=>t.Region==”WA”);

var waCustomers=customers.where(t=>t.Region==”WA”) select c;

both a and b

Show Answer

14

How to remove duplicate elements in a sequence?

var remove=List.Distinct();

var remove=List.ToList()

var remove=List.Remove()

var remove=List.Take(5)

Show Answer

15

How to find the unique Category names?

var categoryNames = (from p in products select p.Category) .Distinct();

var categoryNames=products.select new{p.Category}.Distinct();

var categoryNames=products.Category .Distinct()

Both and c

Show Answer

16

How to create one sequence that contains the unique values from both arrays?

List1.Union(List2);

List1.Concat(List2);

Both

None

Show Answer

17

How to create one sequence that contains the unique first letter from both product and customer names?

products | customers |
---|---|

ProductName | CompanyName |

(from p in products select p.ProductName[0]).Union(from c in customers select c.CompanyName[0]);

(from p in products select p.ProductName[1]).Union(from c in customers select c.CompanyName[1]);

(from p in products select p.ProductName[0]).Concat(from c in customers select c.CompanyName[0]);

a and c

Show Answer

18

How to create one sequence that contains the common values shared by both arrays? int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 }; int[] numbersB = { 1, 3, 5, 7, 8 };

numbersA.Intersect(numbersB);

numbersA.Union(numbersB);

numbersA.Mutual(numbersB);

None

Show Answer

19

) How to create one sequence that contains the common first letter from both product and customer names?

products | customers |
---|---|

ProductName | CompanyName |

(from p in products select p.ProductName[0]). Intersect(from c in customers select c.CompanyName[0]);

(from p in products select p.ProductName[0]).Except(from c in customers select c.CompanyName[0]);

(from p in products select p.ProductName[1]). Intersect (from c in customers select c.CompanyName[1]);

None

Show Answer

20

How to create a sequence that contains the values from numbersA that are not also in numbersB? int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 } int[] numbersB = { 1, 3, 5, 7, 8 };

numbersA.Except(numbersB);

numbersA.NotIn(numbersB);

numbersA. Intersect(numbersB);

None

Show Answer