AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 1 - 5 of 5 questions

1

Correct Declaration of Values to variables ‘a’ and ‘b’?

a

int a = 32, b = 40.6

b

int a = 42; b = 40

c

int a = 32; int b = 40

d

int a = b = 42

correct answer c

a) Although,declaration of ‘b’ and ‘a’ are correct but initialization of value to ‘b’ should be ‘int’ datatype not float.
b) Missing declaration type of ‘b’.
c) correctly declared datatypes ‘a’ and ‘b’.
d) ‘b’ can’t be assigned values before declaration.

2

Select error in the given program :

1.

static Void Main(String[] args)

2.

 {

3.

 constint m =100;

4.

 int n =10;

5.

 constint k = n /5*100* n ;

6.

 Console.WriteLine(m * k);

7.

 Console.ReadLine();

8.

 }

 

 

a

‘k’ should not be declared constant

b

Expression assigned to ‘k’ should be constant in nature

c

Expression (m * k) is invalid

d

m ‘ is declared in invalid format

correct answer b

’k’ should be declared as const int k = 10/5 * 100*10 i.e only constant values should be assigned to a constant.
Output :Error 1 – The expression being assigned to ‘k’ must be constant.

3

Correct output for code is?

1.

 staticvoid Main(string[] args)

2.

 {

3.

 float a = 10.553f;

4.

 long b = 12L;

5.

 int c;

6.

 c = Convert.ToInt32(a + b);

7.

 Console.WriteLine(c);

8.

 }

 

 

 

 

a

23.453

b

22

c

23

d

22.453

correct answer c

The two datatype ‘float’ and ‘long’ after arithmetic operation completely converted to nearest whole number 23.
Output : 23.

4

How many Bytes are stored by ‘Long’ Datatype in C# .net?

a

8

b

4

c

2

d

1

correct answer a

‘Long’ is the datatype keyword used for storing data of unlimited length so by definition its size is always maximum i.e 8.

5

Which Conversion function of ‘Convert.TOInt32()’ and ‘Int32.Parse()’ is efficient?
1) Int32.Parse() is only used for strings and throws argument exception for null string
2) Convert.Int32() used for datatypes and returns directly ‘0’ for null string

a

2

b

Both 1 & 2

c

1

d

None of the mentioned

correct answer a

Convenient for every datatype so mostly preferred

Select a company to compare with

vs

Similar Companies