C# - Test Drive...!!

Description

A small test drive - to evaluate a few important concepts from C#
Prashant  Singh R
Quiz by Prashant Singh R , updated more than 1 year ago
Prashant  Singh R
Created by Prashant Singh R about 6 years ago
207
0

Resource summary

Question 1

Question
What must be different between two overloads of a method?
Answer
  • EITHER the number of parameters OR the return type of each method overload
  • The names of the method overloads
  • EITHER the number of parameters OR the type of at least one parameter
  • EITHER the number of parameters OR the type of at least one parameter OR the return type of each method overload
  • EITHER the names of the method overloads OR their return types

Question 2

Question
Which operator would you use to attach a handler to an event?
Answer
  • =
  • =+
  • +=
  • =>
  • ->

Question 3

Question
Which of the following is a syntactically correct way to declare and initialize an array of "int"?
Answer
  • var x = new int[]{1, 2, 3};
  • int[] x = int[] {1, 2, 3};
  • int[3] x = new int{1, 2, 3};
  • var x = new {1, 2, 3};

Question 4

Question
Consider this implementation of an enumerator. If this is enumerated, at what point will the message "In finally block!" be written to the console?
Answer
  • It won't, the yield return bypasses the finally block.
  • Once, after the first item in the enumeration has been returned.
  • Three times, once after returning each item in the enumeration.
  • Once, after the enumeration is complete.

Question 5

Question
Name an advantage of passing a parameter to a method by reference, compared to passing by value
Answer
  • Passing by reference protects the data in the caller from inadvertant changes to the parameter value inside the called method.
  • 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 allows the method to safely execute on multiple threads simultaneously without risk of corrupting the data in the parameter.

Question 6

Question
In the following code, [System.Web.Services.WebMethod] is an example of which C# language feature?
Answer
  • Functional Property
  • WebMethod
  • Attribute
  • Method-Setting

Question 7

Question
What is the main problem with the following code?
Answer
  • The variable "ex" has been declared twice in the same context.
  • The variable "ex" is not used in the last catch block.
  • Only one "catch" block can be associated with each "try" block.
  • The last "catch" block is unreachable.

Question 8

Question
Write the following LINQ query using method syntax.
Answer
  • var shortNames = names.Where(name => name.Length < 4) .OrderBy(name => name);
  • var shortNames = names.Where(name.Length < 4) .OrderBy(x);
  • var shortNames = names.Where(this.Length < 4) .OrderBy(this);
  • var shortNames = names.Where(this.Length < 4) .OrderBy(this) .Select(this);

Question 9

Question
What is the full name of the "type" that is represented by keyword "long"?
Answer
  • System.Int64
  • System.Long64
  • System.Int
  • System.Int32
  • System.Long

Question 10

Question
What does the "params" keyword do when used in a method parameter list?
Answer
  • Guides the compiler in which overload of a method to choose
  • Allows arguments of any type to be passed to a method
  • 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

Question 11

Question
What happens when the below code is executed? public interface ICar { public int getspeed(); }
Answer
  • Succeed
  • Compile error
  • Warning

Question 12

Question
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(); }
Answer
  • Standard transportation Standard transportation Standard transportation
  • Standard transportation A roof that opens up. Carries seven people.
  • Standard transportation Standard transportation Carries seven people.

Question 13

Question
On the whole, which types can you inherit from ?
Answer
  • Any struct or class that is not marked as sealed
  • Any class that is not marked as sealed
  • Any class
  • Any type except for the C# built-in types (int, bool, string, etc.)

Question 14

Question
Which of these shows the correct way to declare an extension method on "string" called "WordCount()" ?
Answer
  • public static int WordCount (string str) : this str { /* ... */ }
  • public static extension int WordCount (string, string str) { /* ... */ }
  • public extension int string.WordCount(this string str) { /* ... */ }
  • public static int WordCount (this string str) { /* ... */ }

Question 15

Question
What is the visibility of the "CurrentSpeed" property in the following code ? public class Automobile { double CurrentSpeed {get; set;} }
Answer
  • Protected internal
  • Protected
  • Internal
  • Public
  • Private

Question 16

Question
Consider the following code. Which of the following is true about the inner "userResponse" declaration?
Answer
  • 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.

Question 17

Question
What does this code illustrate?
Answer
  • A generic collection
  • A generic method
  • A generic constraint
  • A generic type

Question 18

Question
How can you "modify" the "Manager" constructor declaration so that it passes its parameter to the "Employee" constructor
Answer
  • public Manager(string name) : base(name) { base.ctor(name) /* ... */ }
  • public Manager(string name) : Employee(name) { /* ... */}
  • public Manager(string name) : base(name) { /* ... */}
  • public Manager(string name) { Employee(name) /* ... */ }

Question 19

Question
What will be the execution result of the following code ?
Answer
  • "Hello World!" is displayed in the text block on button click
  • "Hello World!" is displayed in the text block on button click, after 1 second.
  • "Hello World!" is never displayed in the text block
  • "Hello World!" is displayed in the text block on button click, after 10 seconds

Question 20

Question
What will be the execution result of this code (in the console) ?
Answer
  • Prints values from 1 to 10
  • Prints "10" - ten times
  • Throws a compiler error - as del() is not a method
  • Prints "1" - ten times
  • Throws a compiler error - as C# "List" cannot have methods in it
Show full summary Hide full summary

Similar

Evaluation of Explanations of Schizophrenia
Charlotte97
Orbital Mechanics
Luke Hansford
Software Processes
Nurul Aiman Abdu
Module 1: Introduction to Engineering Materials
Kyan Clay
Mathematics
rhiannonsian
AOCS - Attitude and orbit control systems
Luke Hansford
Ordinary Differential Equations
rhiannonsian
audio electronics
Lillian Mehler
Building Structures
Niat Habtemariam
communication system
Lillian Mehler