Upload
kompkar
View
220
Download
0
Embed Size (px)
Citation preview
8/4/2019 C# 2 Fundamentals
1/8
C# 2 fundamental
C# 2.0 Fundmentals
Progress:
Code Sampleusing 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.
8/4/2019 C# 2 Fundamentals
2/8
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
1248Choice 2
1
Choice 3
0357
8/4/2019 C# 2 Fundamentals
3/8
Choice 4
24Choice 5
24816
Int(2/4)Which one of the following C# class modifiers specifies that the class CANNOT be inherited?Choice 1
noninheritableChoice 2
sealedChoice 3
internalChoice 4
abstractChoice 5
final
Which one of the following keywords causes a compile time error if used in a static method?Choice 1
usingChoice 2
8/4/2019 C# 2 Fundamentals
4/8
thisChoice 3
lockChoice 4
fixedChoice 5
continueclass Program{public static readonly int instanceCount;
static void Start( ) {instanceCount = 1;}
}
8/4/2019 C# 2 Fundamentals
5/8
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( ));
8/4/2019 C# 2 Fundamentals
6/8
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 consolebut I don't see how the booleans get there
2) Is the first operator ' | ' considered to be a true/false condition statement?
8/4/2019 C# 2 Fundamentals
7/8
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.GetXGetYFalseGetXFalse
Choice 2.GetXGetYFalseGetX
8/4/2019 C# 2 Fundamentals
8/8
GetYFalse
Choice 3.GetX
GetYTrueGetXGetYTrue
Choice 4.GetXGetYTrueGetXGetYFalse
Choice 5.GetXGetYTrueGetXTrue