Tải bản đầy đủ (.pdf) (10 trang)

Đề thi trắc nghiệm môn C sharp (10)

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (590.8 KB, 10 trang )

Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

91

B.
2, 4
C.
3, 5
D.
4, 5
E.
None of these

10. The C#.NET code snippet given below generates ____ numbers series as output?
int i = 1, j = 1, val;
while (i < 25)
{
Console.Write(j + " ");
val = i + j;
j = i;
i = val;
}
A.
Prime
B.
Fibonacci
C.
Palindrome
D.
Odd
E.


Even



11. Which of the following statements are correct about the C#.NET code snippet given
below?
if (age > 18 && no < 11)
a = 25;
1. The condition no < 11 will be evaluated only if age > 18 evaluates toTrue.
2. The statement a = 25 will get executed if any one condition is True.
3. The condition no < 11 will be evaluated only if age > 18 evaluates toFalse.
4. The statement a = 25 will get executed if both the conditions are True.
5. && is known as a short circuiting logical operator.
A.
1, 3
B.
2, 5
C.
1, 4, 5
D.
3, 4, 5
E.
None of these

12. Which of the following statements are correct?
1. A switch statement can act on numerical as well as Boolean types.
2. A switch statement can act on characters, strings and enumerationstypes.
Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

92


3. We cannot declare variables within a case statement if it is not enclosed by{ }.
4. The foreach statement is used to iterate through the collection to get the desired information
and should be used to change the contents of the collection to avoid unpredictable side
effects.
5. All of the expressions of the for statement are not optional.
A.
1, 2
B.
2, 3
C.
3, 5
D.
4, 5
E.
None of these

13. What will be the output of the C#.NET code snippet given below?
int i = 2, j = i;
if (Convert.ToBoolean((i | j & 5) & (j - 25 * 1)))
Console.WriteLine(1);
else
Console.WriteLine(0);
A.
0
B.
1
C.
Compile Error
D.

Run time Error



14. Which of the following statements is correct about the C#.NET code snippet given
below?
switch (id)
{
case 6:
grp = "Grp B";
break;

case 13:
grp = "Grp D";
break;

case 1:
grp = "Grp A";
break;
Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

93


case ls > 20:
grp = "Grp E";
break ;

case Else:
grp = "Grp F";

break;
}
A.
Compiler will report an error in case ls > 20 as well as in case Else.
B.
There is no error in this switch case statement.
C.
Compiler will report an error only in case Else.
D.
Compiler will report an error as there is no default case.
E.
The order of the first three cases should be case 1, case 6, case 13(ascending).

15. Which of the following is another way to rewrite the code snippet given below?
int a = 1, b = 2, c = 0;
if (a < b) c = a;
A.
int a = 1, b = 2, c = 0;
c = a < b ? a : 0;
B.
int a = 1, b = 2, c = 0;
a < b ? c = a : c = 0;
C.
int a = 1, b = 2, c = 0;
a < b ? c = a : c = 0 ? 0 : 0;
D.
int a = 1, b = 2, c = 0;
a < b ? return (c): return (0);
E.
int a = 1, b = 2,c = 0;

c = a < b : a ? 0;

16. Which of the following statements are correct?
1. The switch statement is a control statement that handles multiple selections and
enumerations by passing control to one of the case statements within its body.
Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

94

2. The goto statement passes control to the next iteration of the enclosing iteration statement in
which it appears.
3. Branching is performed using jump statements which cause an immediate transfer of the
program control.
4. A common use of continue is to transfer control to a specific switch-caselabel or
the default label in a switch statement.
5. The do statement executes a statement or a block of statements enclosed in{} repeatedly
until a specified expression evaluates to false.
A.
1, 2, 4
B.
1, 3, 5
C.
2, 3, 4
D.
3, 4, 5
E.
None of these

17. Which of the following statements are correct about the C#.NET code snippet given
below?

if (age > 18 || no < 11)
a = 25;
1. The condition no < 11 will get evaluated only if age > 18 evaluates toFalse.
2. The condition no < 11 will get evaluated if age > 18 evaluates to True.
3. The statement a = 25 will get evaluated if any one one of the two conditions is True.
4. || is known as a short circuiting logical operator.
5. The statement a = 25 will get evaluated only if both the conditions areTrue.
A.
1, 4, 5
B.
2, 4
C.
1, 3, 4
D.
2, 3, 5
E.
None of these

18. What will be the output of the code snippet given below?
int i;
for(i = 0; i<=10; i++)
{
if(i == 4)
{
Console.Write(i + " "); continue;
}
Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

95


else if (i != 4)
Console.Write(i + " "); else
break;
}
A.
1 2 3 4 5 6 7 8 9 10
B.
1 2 3 4
C.
0 1 2 3 4 5 6 7 8 9 10
D.
4 5 6 7 8 9 10
E.
4



19. Which of the following loop correctly prints the elements of the array?
char[ ] arr = new chart[ ] {'k', 'i','C', 'i','t'} ;
A.
do
{
Console.WriteLine((char) i);
}
while (int i = 0; i < arr; i++);
B.
foreach (int i in arr)
{
Console.WriteLine((char) i);
}

C.
for (int i = 0; i < arr; i++)
{
Console.WriteLine((char) i);
}
D.
while (int i = 0; i < arr; i++)
{
Console.WriteLine((char) i);
}
E.
do
{
Console.WriteLine((char) i);
Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

96

}
until (int i = 0; i < arr; i++);


20. Which of the following statements is correct about the C#.NET code snippet given
below?
int i, j, id = 0; switch (id)
{
case i:
Console.WriteLine("I am in Case i");
break;


case j:
Console.WriteLine("I am in Case j");
break;
}
A.
The compiler will report case i and case j as errors since variables cannot be used in
cases.
B.
Compiler will report an error since there is no default case in the switch
case statement.
C.
The code snippet prints the result as "I am in Case i"".
D.
The code snippet prints the result as "I am in Case j".
E.
There is no error in the code snippet.



Câu hỏi namespaces
1. Which of the followings are NOT a .NET namespace?
1. System.Web
2. System.Process
3. System.Data
4. System.Drawing2D
5. System.Drawing3D
A.
1, 3
B.
2, 4, 5

C.
3, 5
Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

97

D.
1, 2, 3

2. Which of the following statements is correct about namespaces in C#.NET?
A.
Namespaces can be nested only up to level 5.
B.
A namespace cannot be nested.
C.
There is no limit on the number of levels while nesting namespaces.
D.
If namespaces are nested, then it is necessary to use using statement while using the
elements of the inner namespace.
E.
Nesting of namespaces is permitted, provided all the inner namespaces are declared in the
same file.

3. Which of the following is correct way to rewrite the C#.NET code snippet given below?
using Microsoft.VisualBasic;
using System.Windows.Forms;
MessageBox.Show("Wait for a" + ControlChars.CrLf + "miracle");
A.
using System.Windows.Forms;
using CtrlChars = Microsoft.VisualBasic.ControlChars;

MessageBox.Show("Wait for a" + CrLf + "miracle");
B.
using Microsoft.VisualBasic;
using System.Windows.Forms;
CtrlChars = ControlChars;
MessageBox.Show("Wait for a" + CtrlChars.CrLf + "miracle");
C.
using Microsoft.VisualBasic;
using System.Windows.Forms;
CtrlChars = ControlChars;
MessageBox.Show ("Wait for a" + CrLf + "miracle");
D.
using System.Windows.Forms;
using CtrlChars = Microsoft.VisualBasic.ControlChars;
MessageBox.Show("Wait for a" + CtrlChars.CrLf + "miracle");

4. Which of the following statements is correct about the using statement used in C#.NET?
A.
using statement can be placed anywhere in the C#.NET source code file.
B.
It is permitted to define a member at namespace level as a using alias.
Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

98

C.
A C#.NET source code file can contain any number of using statement.
D.
By using using statement it is possible to create an alias for the namespace but not for the
namespace element.

E.
By using using statement it is possible to create an alias for the namespace element but
not for the namespace.


5. Which of the following statements are correct about a namespace used in C#.NET?
1. Classes must belong to a namespace, whereas structures need not.
2. Every class, struct, enum, delegate and interlace has to belong to some or the other
namespace.
3. All elements of the namespace have to belong to one file.
4. If not mentioned, a namespace takes the name of the current project.
5. The namespace should be imported to be able to use the elements in it.
A.
1, 3
B.
2, 4, 5
C.
3, 5
D.
4 only

6. Which of the following CANNOT belong to a C#.NET Namespace?
A.
class
B.
struct
C.
enum
D.
Data

E.
interface





7. Which of the following statements is correct about a namespace used in C#.NET?
A.
Nested namespaces are not allowed.
B.
Importing outer namespace imports inner namespace.
C.
Nested namespaces are allowed.
D.
If nested, the namespaces cannot be split across files.

8. Which of the following C#.NET code snippets will correctly print "Hello C#.NET"?
A.
import System;
Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

99

namespace IndiabixConsoleApplication
{
class MyProgram
{
static void Main(string[] args)
{

Console.WriteLine("Hello C#.NET");
}
}
}
B.
using System;
namespace IndiabixConsoleApplication
{
class MyProgram
{
static void Main(string[ ] args)
{
WriteLine("Hello C#.NET");
}
}
}
C.
using System.Console;
namespace IndiabixConsoleApplication
{
class MyProgram
{
static void Main (string[ ] args)
{
WriteLine("Hello C#.NET");
}
}
}
D.
using System;

namespace IndiabixConsoleApplication
{
class MyProgram
{
static void Main(string[] args)
{
Console.WriteLine("Hello C#.NET");
}
}
Câu hỏi trắc nghiệm C# bằng tiếng anh có đáp án

100

}


9. If ListBox is class present in System.Windows.Forms namespace, then which of the
following statements are the correct way to create an object of ListBox Class?
1. using System.Windows.Forms;
2. ListBox lb = new ListBox();
3. using LBControl = System.Windows.Forms;
4. LBControl lb = new LBControl();
5. System.Windows.Forms.ListBox lb = new System.Windows.Forms.ListBox();
6. using LBControl lb = new System.Windows.Forms.ListBox;
7. using LBControl = System.Windows.Forms.ListBox;
8. LBControl lb = new LBControl();
A.
1, 3
B.
2, 4, 5

C.
1, 3, 5
D.
5 only


×