0% found this document useful (0 votes)
63 views

Quiz Prn211

The document is a quiz with 13 multiple choice questions about C# programming concepts. It covers topics like passing parameters by value and reference, static constructors, inheritance, overriding, events, and viewing file headers in assemblies. The questions ask about analyzing code snippets and predicting program output. The document is formatted as a study guide with the questions and multiple choice answers presented across several pages.

Uploaded by

Pea Tee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Quiz Prn211

The document is a quiz with 13 multiple choice questions about C# programming concepts. It covers topics like passing parameters by value and reference, static constructors, inheritance, overriding, events, and viewing file headers in assemblies. The questions ask about analyzing code snippets and predicting program output. The document is formatted as a study guide with the questions and multiple choice answers presented across several pages.

Uploaded by

Pea Tee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Checklist :

I. Q & A
II. Ôn tập Quizzes
Các bạn xem bài
thật kỹ rồi Q & A ?

Page 1
Quizzes Review PRN292
Q1. For the following program :
static void Test(int a, out int b, ref int c)
{
b = 2;
a = c++;
b = a + c;
c = ++b;
return ;
}
static void Main(string[] args)
{
int a = 2, b = 3, c = 1;
Test(c, out a, ref b);
Console.WriteLine("a:{0},b:{1},c:{2}", a, b, c);
Console.WriteLine();
}
The output will be :
A: a=4,b=4,c=1
B: a=3,b=4,c=3
C: a=8,b=8,c=1
D: a=4,b=4,c=3

Page 2
Q2. For the following program :
static void Test(out int a, ref int b)
{
int t = a;
a = b;
b = t;
}
static void Main(string[] args)
{
int a = 2, b = 1;
Test(out a, ref b);
Console.WriteLine("a:{0},b:{1}", a, b);
Console.WriteLine();
}
The output will be :
A: a=1,b=2
B: a=2,b=1
C: An exception wil be thrown.
D: Compile-time error

Page 3
Q3. For the following program :
class A
{
static A() {
Console.Write("1");
}
public A()
{
Console.Write("2");
}
public static void Print()
{
Console.Write("3");
}
}
class Program {
static void Main(string[] args)
{
A.Print();
Console.WriteLine();
}
}
The output will be :
A: 13
B: 12
C: An exception will be thrown.
D: 21

Page 4
Q4: For the following program :
static T Test<T>(T a, T b)
{
a++;
++b;
T c = a + b;
return c;
}
static void Main(string[] args)
{
int a = 3, b = 4;
Console.WriteLine(Test<int>(a, b));
}
The output will be :
a:7
b:8
c:9
d: Compile-time error

Page 5
Q5: . For the table named Products:
Products ( Id int key, Name varchar(30) )
Records had inserted:
[ {1,'Milk'} , {2,'Coffee'} ]
For the following program :
string strConnection =
@"server =(local);database=abc;uid=sa;pwd=123";
string SQL = "select * from Products";
SqlConnection cnn = new SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand(SQL, cnn);
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read()) {
Console.WriteLine(rd.GetString(1));
}
cnn.Close();
The output will be :
a.Milk Coffee
b.Coffee Milk
c.Compiled-time error
d.Run-time error

Q6: For the table named Products:

Page 6
Products ( Id int key, Quantity int )
Records has inserted:
[ {1, 20 } , {2, 10} ]
For the following program :
string strConnection =
@"server=(local);database=abc;uid=sa;pwd=123";
string SQL = "select * from Products";
SqlConnection cnn = new
SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand(SQL, cnn);
cnn.Open();
SqlDataReader rd = cmd.ExecuteReader();
Console.WriteLine(rd.FieldCount);
cnn.Close();
The output will be :
a. 2
b. 1
c. Compiled-time error
d. Run-time error

Page 7
Q7. For the following program :
class A{
static A() {
Console.Write("A");
}
public A()
{
Console.Write("B");
}
public void Print()
{
Console.Write("C");
}
}
class Program {
static void Main(string[] args)
{
new A().Print();
Console.WriteLine();
}
}
The output will be :
A: BAC
B: ABC
C: CAB
D: ACB

Page 8
Q8. For the following program :
class A{
int x = 1;
public A() {
x = 3;
}
public void Print()
{
Console.Write(x);
}
}
class B : A
{
int x;
public B() {
x = 5;
}
}
class Program {
static void Main(string[] args)
{
B b1 = new B();
b1.Print();
Console.WriteLine();
}
}
The output will be :
A: 3
B: 1
C: 5
D: An exception will be thrown.

Page 9
Q9. For the following program
class A{
int x ;
public A() {
x = 3;
}
public void Print()
{
Console.Write(x);
}
}
class B : A
{
int x;
public B() {
x = 2;
}
public new void Print()
{
Console.Write(x);
}
}
class Program {
static void Main(string[] args)
{
A a = new B();
a.Print();
Console.WriteLine();
}
}
The output will be :
A: 3
B: 2
C: Compile-time error
D: Run-time error

Page 10
Q10. For the following program
class A{
public void Print(){
Console.Write("A");
}
}
class B {
public void Display(){
Console.Write("B");
}
}

class Program {
delegate void test();
static void Main(string[] args)
{
test t = new test(new A().Print);
t += new B().Display;
t();
Console.WriteLine();
}
}
The output will be :
A: AB
B: BA
C: Compile-time error.
D: An exception will be thrown.

Page 11
Q11. For the following program
class A{
public virtual void Print(){
Console.Write("Hello");
}
}
class B : A {
public override void Print(){
Console.Write("Hi");
}
}
class Program {
static void Main(string[] args)
{
A a = new B();
a.Print();
Console.ReadLine();
}
}
The output will be :
A: Hi
B: Hello
C: Error because can not assign an instance of B to a
D: The output will be “Hi” if replace “override” by “new”
keyword

Page 12
Q12. For the following program
public delegate void SimpleDelegateHandler(int x);
class Program {
int s = 0;
public event SimpleDelegateHandler myEvent;
public void run(int n) {
myEvent += delegate (int x) {
s = x * x;
};
myEvent += delegate {
Console.WriteLine("{0}",s);
};
myEvent(n);
}
static void Main(string[] args)
{
new Program().run(3);
Console.ReadLine();
}
}
The output will be :
A: 9
B: 0
C: 3
D: An exception will be thrown.

Page 13
Q13.

Which of the following statement to view Win32


File Header of MathLibrary.dll ?

a.dumpbin /headers MathLibrary.dll


b.dumpbin /head MathLibrary.dll
c.dumpbin /clr MathLibrary.dll
d.dumpbin /headview MathLibrary.dll

Page 14
Q14.

Which of the following are members in the


assemblies ?
1. Manifest
2. CIL code
3. Type metadata
4. Media Resources
5. Machine code
a.1, 3 , 4 & 5
b.1 , 2 & 5
c.2, 3 & 4
d.1, 2 & 3

Page 15

You might also like