Quiz
C# - Test Drive...!!
Este quiz tem tempo limite, por isso abre no player de sempre.
Perguntas do quiz (20)
1What must be different between two overloads of a method?
- AEITHER the number of parameters OR the return type of each method overload
- BThe names of the method overloads
- CEITHER the number of parameters OR the type of at least one parameter
- DEITHER the number of parameters OR the type of at least one parameter OR the return type of each method overload
- EEITHER the names of the method overloads OR their return types
2Which operator would you use to attach a handler to an event?
- A=
- B=+
- C+=
- D=>
- E->
3Which of the following is a syntactically correct way to declare and initialize an array of "int"?
- Avar x = new int[]{1, 2, 3};
- Bint[] x = int[] {1, 2, 3};
- Cint[3] x = new int{1, 2, 3};
- Dvar x = new {1, 2, 3};
4Consider this implementation of an enumerator.
If this is enumerated, at what point will the message "In finally block!" be written to the console?- AIt won't, the yield return bypasses the finally block.
- BOnce, after the first item in the enumeration has been returned.
- CThree times, once after returning each item in the enumeration.
- DOnce, after the enumeration is complete.
5Name an advantage of passing a parameter to a method by reference, compared to passing by value
- APassing by reference protects the data in the caller from inadvertant changes to the parameter value inside the called method.
- BIf the method throws an exception, passing by reference preserves more information in the stack trace.
- CIf the parameter is large, passing by reference saves data copying and can therefore be quicker.
- DPassing by reference allows the method to safely execute on multiple threads simultaneously without risk of corrupting the data in the parameter.
6In the following code, [System.Web.Services.WebMethod] is an example of which C# language feature?
- AFunctional Property
- BWebMethod
- CAttribute
- DMethod-Setting
7What is the main problem with the following code?
- AThe variable "ex" has been declared twice in the same context.
- BThe variable "ex" is not used in the last catch block.
- COnly one "catch" block can be associated with each "try" block.
- DThe last "catch" block is unreachable.
8Write the following LINQ query using method syntax.
- Avar shortNames = names.Where(name => name.Length < 4)
.OrderBy(name => name); - Bvar shortNames = names.Where(name.Length < 4)
.OrderBy(x); - Cvar shortNames = names.Where(this.Length < 4)
.OrderBy(this); - Dvar shortNames = names.Where(this.Length < 4)
.OrderBy(this)
.Select(this);
- Avar shortNames = names.Where(name => name.Length < 4)
9What is the full name of the "type" that is represented by keyword "long"?
- ASystem.Int64
- BSystem.Long64
- CSystem.Int
- DSystem.Int32
- ESystem.Long
10What does the "params" keyword do when used in a method parameter list?
- AGuides the compiler in which overload of a method to choose
- BAllows arguments of any type to be passed to a method
- CAllows individual arguments to be omitted, with default values supplied, when calling the method
- DAllows a variable number of arguments to be used when a method is called
11What happens when the below code is executed?
public interface ICar
{ public int getspeed(); }- ASucceed
- BCompile error
- CWarning
12class 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();
}- AStandard transportation
Standard transportation
Standard transportation - BStandard transportation
A roof that opens up.
Carries seven people. - CStandard transportation
Standard transportation
Carries seven people.
- AStandard transportation
13On the whole, which types can you inherit from ?
- AAny struct or class that is not marked as sealed
- BAny class that is not marked as sealed
- CAny class
- DAny type except for the C# built-in types (int, bool, string, etc.)
14Which of these shows the correct way to declare an extension method on "string" called "WordCount()" ?
- Apublic static int WordCount (string str) : this str
{ /* ... */ } - Bpublic static extension int WordCount (string, string str)
{ /* ... */ } - Cpublic extension int string.WordCount(this string str)
{ /* ... */ } - Dpublic static int WordCount (this string str)
{ /* ... */ }
- Apublic static int WordCount (string str) : this str
15What is the visibility of the "CurrentSpeed" property in the following code ?
public class Automobile
{ double CurrentSpeed {get; set;} }- AProtected internal
- BProtected
- CInternal
- DPublic
- EPrivate
16Consider the following code.
Which of the following is true about the inner "userResponse" declaration?- AIt will cause a compiler error because the name conflicts with the first userResponse declaration
- BIt will not allocate a new variable, but will instead overwrite the contents of the outer userResponse variable.
- CIt will cause a compiler error because you cannot declare local variables inside a foreach loop.
- DIt will cause the outer userResponse variable to be hidden within the foreach loop.
17What does this code illustrate?
- AA generic collection
- BA generic method
- CA generic constraint
- DA generic type
18How can you "modify" the "Manager" constructor declaration so that it passes its parameter to the "Employee" constructor
- Apublic Manager(string name) : base(name)
{
base.ctor(name)
/* ... */
} - Bpublic Manager(string name) : Employee(name)
{ /* ... */} - Cpublic Manager(string name) : base(name)
{ /* ... */} - Dpublic Manager(string name)
{
Employee(name)
/* ... */
}
- Apublic Manager(string name) : base(name)
19What will be the execution result of the following code ?
- A"Hello World!" is displayed in the text block on button click
- B"Hello World!" is displayed in the text block on button click, after 1 second.
- C"Hello World!" is never displayed in the text block
- D"Hello World!" is displayed in the text block on button click, after 10 seconds
20What will be the execution result of this code (in the console) ?
- APrints values from 1 to 10
- BPrints "10" - ten times
- CThrows a compiler error - as del() is not a method
- DPrints "1" - ten times
- EThrows a compiler error - as C# "List" cannot have methods in it
Informações
- Descrição
- A small test drive - to evaluate a few important concepts from C#
- Autor
- Prashant Singh R
- Idioma
- English
- Visualizações
- 251
- Etiquetas
- Avaliação
- 5,0 de 5 · 1 avaliação Avalie este quiz