Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
Prashant  Singh R
Quiz by , created more than 1 year ago

A small test drive - to evaluate a few important concepts from C#

219
0
0
Prashant  Singh R
Created by Prashant Singh R over 6 years ago
Rate this resource by clicking on the stars below:
1 2 3 4 5 (1)
Ratings (1)
1
0
0
0
0

0 comments

There are no comments, be the first and leave one below:

Close

C# - Test Drive...!!

Each question in this quiz is timed.

Begin Quiz

Question 11 of 20 Question 1 of 20

10

What must be different between two overloads of a method?

Select one of the following:

  • EITHER the number of parameters OR the type of at least one parameter OR the return type of each method overload

  • The names of the method overloads

  • EITHER the number of parameters OR the return type of each method overload

  • EITHER the names of the method overloads OR their return types

  • EITHER the number of parameters OR the type of at least one parameter

Explanation

Question 8 of 20 Question 2 of 20

10

Which operator would you use to attach a handler to an event?

Select one of the following:

  • =

  • =>

  • =+

  • +=

  • ->

Explanation

Question 10 of 20 Question 3 of 20

10

Which of the following is a syntactically correct way to declare and initialize an array of "int"?

Select one of the following:

  • var x = new int[]{1, 2, 3};

  • int[3] x = new int{1, 2, 3};

  • int[] x = int[] {1, 2, 3};

  • var x = new {1, 2, 3};

Explanation

Question 9 of 20 Question 4 of 20

20

Consider this implementation of an enumerator.
If this is enumerated, at what point will the message "In finally block!" be written to the console?

Select one of the following:

  • It won't, the yield return bypasses the finally block.

  • Once, after the enumeration is complete.

  • Once, after the first item in the enumeration has been returned.

  • Three times, once after returning each item in the enumeration.

Explanation

Question 16 of 20 Question 5 of 20

15

Name an advantage of passing a parameter to a method by reference, compared to passing by value

Select one of the following:

  • If the method throws an exception, passing by reference preserves more information in the stack trace.

  • If the parameter is large, passing by reference saves data copying and can therefore be quicker.

  • Passing by reference protects the data in the caller from inadvertant changes to the parameter value inside the called method.

  • Passing by reference allows the method to safely execute on multiple threads simultaneously without risk of corrupting the data in the parameter.

Explanation

Question 20 of 20 Question 6 of 20

10

In the following code, [System.Web.Services.WebMethod] is an example of which C# language feature?

Select one of the following:

  • WebMethod

  • Attribute

  • Functional Property

  • Method-Setting

Explanation

Question 7 of 20 Question 7 of 20

15

What is the main problem with the following code?

Select one of the following:

  • Only one "catch" block can be associated with each "try" block.

  • The last "catch" block is unreachable.

  • The variable "ex" has been declared twice in the same context.

  • The variable "ex" is not used in the last catch block.

Explanation

Question 12 of 20 Question 8 of 20

20

Write the following LINQ query using method syntax.

Select one of the following:

  • var shortNames = names.Where(this.Length < 4)
    .OrderBy(this);

  • var shortNames = names.Where(name.Length < 4)
    .OrderBy(x);

  • var shortNames = names.Where(name => name.Length < 4)
    .OrderBy(name => name);

  • var shortNames = names.Where(this.Length < 4)
    .OrderBy(this)
    .Select(this);

Explanation

Question 19 of 20 Question 9 of 20

10

What is the full name of the "type" that is represented by keyword "long"?

Select one of the following:

  • System.Long

  • System.Long64

  • System.Int32

  • System.Int

  • System.Int64

Explanation

Question 14 of 20 Question 10 of 20

15

What does the "params" keyword do when used in a method parameter list?

Select one of the following:

  • Guides the compiler in which overload of a method to choose

  • Allows individual arguments to be omitted, with default values supplied, when calling the method

  • Allows a variable number of arguments to be used when a method is called

  • Allows arguments of any type to be passed to a method

Explanation

Question 13 of 20 Question 11 of 20

10

What happens when the below code is executed?

public interface ICar
{ public int getspeed(); }

Select one of the following:

  • Compile error

  • Warning

  • Succeed

Explanation

Question 18 of 20 Question 12 of 20

15

class Car
{
public void DescribeCar()
{
ShowDetails();
}
public virtual void ShowDetails()
{
System.Console.WriteLine("Standard transportation.");
}
}

class ConvertibleCar : Car
{
public new void ShowDetails()
{
System.Console.WriteLine("A roof that opens up.");
}
}

class Minivan : Car
{
public override void ShowDetails()
{
System.Console.WriteLine("Carries seven people.");
}
}

public static void TestCars1()
{

Car car1 = new Car();
car1.DescribeCar();
ConvertibleCar car2 = new ConvertibleCar();
car2.DescribeCar();
Minivan car3 = new Minivan();
car3.DescribeCar();
}

Select one of the following:

  • Standard transportation
    Standard transportation
    Carries seven people.

  • Standard transportation
    Standard transportation
    Standard transportation

  • Standard transportation
    A roof that opens up.
    Carries seven people.

Explanation

Question 6 of 20 Question 13 of 20

15

On the whole, which types can you inherit from ?

Select one of the following:

  • Any type except for the C# built-in types (int, bool, string, etc.)

  • Any struct or class that is not marked as sealed

  • Any class

  • Any class that is not marked as sealed

Explanation

Question 5 of 20 Question 14 of 20

20

Which of these shows the correct way to declare an extension method on "string" called "WordCount()" ?

Select one of the following:

  • public extension int string.WordCount(this string str)
    { /* ... */ }

  • public static int WordCount (this string str)
    { /* ... */ }

  • public static extension int WordCount (string, string str)
    { /* ... */ }

  • public static int WordCount (string str) : this str
    { /* ... */ }

Explanation

Question 4 of 20 Question 15 of 20

10

What is the visibility of the "CurrentSpeed" property in the following code ?
public class Automobile
{ double CurrentSpeed {get; set;} }

Select one of the following:

  • Public

  • Internal

  • Protected internal

  • Private

  • Protected

Explanation

Question 1 of 20 Question 16 of 20

10

Consider the following code.
Which of the following is true about the inner "userResponse" declaration?

Select one of the following:

  • It will cause a compiler error because the name conflicts with the first userResponse declaration

  • It will not allocate a new variable, but will instead overwrite the contents of the outer userResponse variable.

  • It will cause a compiler error because you cannot declare local variables inside a foreach loop.

  • It will cause the outer userResponse variable to be hidden within the foreach loop.

Explanation

Question 17 of 20 Question 17 of 20

10

What does this code illustrate?

Select one of the following:

  • A generic type

  • A generic method

  • A generic collection

  • A generic constraint

Explanation

Question 3 of 20 Question 18 of 20

20

How can you "modify" the "Manager" constructor declaration so that it passes its parameter to the "Employee" constructor

Select one of the following:

  • public Manager(string name) : Employee(name)
    { /* ... */}

  • public Manager(string name) : base(name)
    {
    base.ctor(name)
    /* ... */
    }

  • public Manager(string name) : base(name)
    { /* ... */}

  • public Manager(string name)
    {
    Employee(name)
    /* ... */
    }

Explanation

Question 15 of 20 Question 19 of 20

20

What will be the execution result of the following code ?

Select one of the following:

  • "Hello World!" is displayed in the text block on button click, after 10 seconds

  • "Hello World!" is displayed in the text block on button click, after 1 second.

  • "Hello World!" is displayed in the text block on button click

  • "Hello World!" is never displayed in the text block

Explanation

Question 2 of 20 Question 20 of 20

20

What will be the execution result of this code (in the console) ?

Select one of the following:

  • Throws a compiler error - as del() is not a method

  • Prints "10" - ten times

  • Prints values from 1 to 10

  • Prints "1" - ten times

  • Throws a compiler error - as C# "List" cannot have methods in it

Explanation