AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 71 - 80 of 174 questions

71

A preprocessor is a program

a

(A)That processes its input data to produce output that is used as input to another program

b

(B)That is nothing but a loader

c

(C)That links various source files

d

(D)All of the mentioned

correct answer a
72

What is the output of the following set of code ?

staticvoid Main(string[] args)

{

     int i, j;

     int[, ] arr =newint[3, 3];

     for(i =0; i <3;++i)

     {

          for(j =0; j <3;++j)

          {

               arr[i, j]= i *2+ i *2;

               Console.WriteLine(arr[i, j]);

          }

         Console.ReadLine();

     }

}

 

 

 

 

 

 

a

0,0,0 4,4,4 8,8,8

b

4,4,4 8,8,8 12,12,12

c

8,8,8 12,12,12 16,16,16

d

0,0,0 1,1,1, 2,2,2

correct answer a

Since,with each value of of ‘i’ the value of ‘j’ is executed three times i.e
for i = 0, j = 0, 0, 0, i = 1, j = 2, 2, 2.
Output: 0, 0, 0 4, 4, 4 8, 8, 8.

73

What is the output for the following set of code ?

staticvoid Main(string[] args)

{

     double a =345.09;

     byte c =(byte) a;

     Console.WriteLine(c);

     Console.ReadLine();

}

 

 

 

a

98

b

89

c

88

d

84

correct answer b

Type casting a larger variable into a smaller variable results in modules of larger variable by range of smaller variable. a is ‘345.09’ which is larger than byte’s range i:e -128 to 127.
Output : 89.

74

Which is the correct way of defining and initializing an array of 3 integers?

a

int[] a={78, 9, 54};

b

int[] a;
a = new int[3];
a[1] = 78;
a[2] = 9;
a[3] = 54;

c

int[] a;
a = new int{78, 9, 54};

d

int[] a;
a = new int[3]{78, 9, 54};

correct answer a,d

Answer: Option (A) and Option (D)

75

What is the output for the following set of code?

staticvoid Main(string[] args)

{

     char A ='K';

     char B = Convert.ToChar(76);

     A++;

     B++;

     Console.WriteLine(A+" "+B);

     Console.ReadLine();

}

 

 

a

M L

b

U L

c

L M

d

A B

correct answer c

“++” increments the value of character by 1. A and B are given values K and 76, when we use increment operator their values increments by 1, A and B becomes L and M.
Output: L, M.

76

Choose selective differences between an array in c# and array in other programming languages.

 

a

Declaring array in C# the square bracket([]) comes after the type but not after identifier

b

It is not necessary to declare size of an array with its type

c

No difference between declaration of array in c# as well as as in other programming languages

d

All of the above mentioned

correct answer a,b

1. When declaring an array in C#, the square brackets ([]) come after the type, not the identifier.Brackets after the identifier is
not legal syntax in C#.
example : int[] IntegerArray;
2. The size of the array is not part of its type as it is in the C language. This allows to declare an array and assign any array
of int objects to it, regardless of the array’s length.
int[] IntegerArray;
IntegerArray = new int[10];
IntegerArray = new int[50];

77

Difference between keywords 'var' and 'dynamic' is:

a

‘Var’ is introduced in C# (3.0) and ‘Dynamic’ is introduced in C# (4.0)

b

‘Var’ is a type of variable where declaration is done at compile time by compiler while ‘Dynamic’ declaration is achieved at runtime by compiler

c

For ‘Var’ Error is caught at compile time and for ‘Dynamic’ Error is caught at runtime

d

For ‘Var’ datatype the code as : var obj1 = 1; and var obj1=”I am a string” will also compile safely.For ‘Dynamic’ datatype the code as: dynamic obj1 =1; and dynamic obj1 = “I am a string” will create an error

correct answer a,b,c

Answer: Option (A), (B) and (C)

78

Select output of the given set of Code :

staticvoid Main(string[] args)

{

     String name ="Dr.Gupta";

     Console.WriteLine("Good Morning"+ name);

}

 

a

Dr.Gupta

b

Good Morning

c

Good Morning Dr.Gupta

d

Good Morning name

correct answer c

How to intialize a string variable and concatenate string using ‘+’ operator.
Output:Good Morning Dr.Gupta

79

Select output for the following set of code.

staticvoid Main(string[] args)

{

     int a =5;

     int b =10;

     int c;

     Console.WriteLine(c = a---++b);

     Console.WriteLine(b);

     Console.ReadLine();

}

 

 

 

 

a

-7, 10

b

-5, 11

c

-6, 11

d

15, 11

correct answer c

Answer: Option (C)

80

Which of these keywords is not a part of exception handling?

a

try

b

finally

c

thrown

d

catch

correct answer c

Exception handling is managed via 5 keywords – try, catch, throws, throw and finally.

Select a company to compare with

vs

Similar Companies