Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. The output of the following code is ______ static void Main(string[] args) {

ID: 3860794 • Letter: 1

Question

1. The output of the following code is ______

static void Main(string[] args)

{

int[] nums = { 1, 0, 6, -2, -4, 3};

var posNums = from n in nums where n % 2 == 0 select n;

foreach (int i in posNums)        

Console.Write(i + " ");

}

2. Which of following is correct for the blank?

static void Main(string[] args)

{ int[] nums = { 8, -2, -1, 2, 6, -4, 5 };

int count = /*_________________ */ ;

Console.WriteLine("The number of positive numbers is: " + count);

Console.ReadLine(); }

3.

using System;

using System.Linq;

using System.Data.Linq;

using System.Xml.Linq;

using System.Collections;

and that the following array is defined:

string[] colors = { ""green"", ""brown"", ""blue"", ""red"" };

var query = from c in colors where c.Length > 3 orderby c.Length select c;

what type is variable query?

4. In current .NET Framework, what assembly must be included in a project to use the SoundPlayer class?

5. If two classes of the same name occur in two different namespaces and both namespaces are used (included) what must be done when using the classes?

6. For a method of a class to be overridden in a subclass which of the following must occur.

7. If a method is marked as protected internal, who can access it?

8. What is the .NET class that every other class is derived from?

9. The class SmithKarenCreature inherits from the class Creature . An instance of SmithKarenCreature is created and referenced in the variable kCreature using the following code: SmithKarenCreature kCreature = new SmithKarenCreature();

A variable called creature of type Creature is declared and kCreature is cast as type Creature and assigned to creature using the following line of code:

Creature creature = (Creature)kCreature;

Which of the following is an alternative syntax to the above line of code?

10. Why does a syntax error occur when trying to declare a variable called 'lock'?

1 0 6 -2 -4 3

Explanation / Answer

ANSWERS:

1) B) 0 6 -2 -4

2) C) (from n in nums where n > 0 select n).Count();

the .Count() function will count the positive numbers selected by the statement

3) C) IENUMERABLE

the query returns IENUMERABLE<string>

4) B) System.Media

This is the media assembly present in .NET Framework

5) B) Provide a fully qualified path to the class that includes the name space and the name of the class

This is the main reason behind creating namespace so that two classes of same name can be used

6) A) The method must be declared as virtual

To override a method the method must be declared virual and when overriding the override keyword is used

7) A) Classes that are both in the same assembly and derived from the declaring class

The protected internal make the code accessible to all part of code in the assembly and also to the deriving class from any other assembly

8) A) System

System is the ultimate base class in the .NET FRAMEWORK Every class is derived from it

9) B) Creature creature = kCreature as Creature;

as keyword is typically used to cast the object to specified object and if it fails to cast then it returns null

10) C) 'locl' is a reserved keyword

lock is in the list of reserved keywords that are used in .NET