You are on page 1of 8

C# 2 fundamental

C# 2.0 Fundmentals Progress: Code Sample using System; namespace App { static delegate int Add(ref int a, ref int b); class Program { static void Main(string[] args) { Add d = delegate(ref int a, ref int b) { Console.WriteLine(a + b); a++; b++; return a + b; }; int x = 1; int y = 1; Console.WriteLine(d(ref x, ref y)); } } } Which one of the following correctly describes the error in the above code sample? Choice 1 Delegates may not be static.

Choice 2 Delegates may not have a return type. Choice 3 a and b are uninitialized since they are declared with the ref keyword. Choice 4 The ref keyword may not be used with anonymous methods. Choice 5 x and y may not be set before calling the delegate. C# 2.0 Fundmentals, Question 1 of 40

Number Sample

Which one of the following is the output of the application in the number sample above? Choice 1 1 2 4 8 Choice 2 1 Choice 3 0 3 5 7

Choice 4 2 4 Choice 5 2 4 8 16

Int(2/4) Which one of the following C# class modifiers specifies that the class CANNOT be inherited? Choice 1 noninheritable Choice 2 sealed Choice 3 internal Choice 4 abstract Choice 5 final Which one of the following keywords causes a compile time error if used in a static method? Choice 1 using Choice 2

this Choice 3 lock Choice 4 fixed Choice 5 continue class Program { public static readonly int instanceCount; static void Start( ) { instanceCount = 1; } }

C# 2.0 Fundmentals Progress:

Delegate Sample

Which one of the following is the output of the code in the delegate sample above when new A( ).Run( ) is executed? Choice 1 10

int? x = 5; Console.WriteLine(x.GetType( ));

1: Int32.Parse("two"); 2: Int32.TryParse("two", out i); Which one of the following is true regarding the two lines in the above Int32 sample? Choice 1 The top line returns only an integer; in the bottom line, "i" can be of any numeric data type. Choice 2 The top line returns an integer by value; the bottom line sends back an integer by reference. Choice 3 The top line does not compile because the compiler will see invalid data; the bottom line compiles as is. Choice 4 The top line does not compile outside of a try/catch block; the bottom can be placed anywhere. Choice 5 The top line throws an exception when Parse fails; the bottom line returns false.

C# 2.0 Fundmentals, Question 16 of 40

The answer to the question below is (5). I have three questions: 1) I don't understand how the boolean gets printed. I can see how the strings are output to the console but I don't see how the booleans get there 2) Is the first operator ' | ' considered to be a true/false condition statement?

3) Is the second operator ' || ' considered to be an 'Or' condition statement? Thanks!

public static void Main(string[] args) { System.Console.WriteLine(GetX() | GetY()); System.Console.WriteLine(GetX() || GetY()); } public static bool GetX() { System.Console.WriteLine("GetX"); return true; } public static bool GetY() { System.Console.WriteLine("GetY"); return false; } Given the sample code above, what is the console output? Choice 1. GetX GetY False GetX False Choice 2. GetX GetY False GetX

GetY False Choice 3. GetX GetY True GetX GetY True Choice 4. GetX GetY True GetX GetY False Choice 5. GetX GetY True GetX True

You might also like