C Sharp tutorials
C Sharp tutorials
1. Every C# program requires at least one main static class. True or False
3. How do value and reference types differ in their use of memory? Why might this be
important?
int x = 10;
float y = 20;
x = y;
5. What are the values of the variables w, x, y and z after this code has executed?
Explain.
int c = 0;
int w = 0, x = 0, y = 0, z = 0;
switch( c ) {
case 0:
w = 10;
goto case 1; // this is required in the current version of C#
case 1:
x = 10;
goto case 2; // as is this
case 2:
y= 10;
break;
case 3:
z= 10;
break;
// the “goto” is not required for empty cases, e.g.,
//case 4:
//case 5:
//case 6:
//case 7: ...some code...
}
6. Now assume that c is initialized to 2 instead of 0, and the code from Question 6 is run
again. What are the values of the variables w, x, y, and z after execution?
7. When the following code has finished executing, what is the value of x?
SWE2 Page 1 on 3
int x = 0;
while( x < 10 )
x++;
int x = 0;
for( int y = 0; y < 10; y += 2 ) {
if( y == 4 )
break;
x++;
}
int x = 10;
int y = x;
y = 20;
10. Can a class have the following two functions defined at the same time?
11. Can a class have the following two functions defined at the same time?
12. Give a C# programming example, including any needed explanation, of the use of
polymorphism.
SWE2 Page 2 on 3
b. Will the CombatShip class compile? Explain.
SWE2 Page 3 on 3