AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 111 - 120 of 174 questions

111

Choose the correct output for the given set of code:

class program

{

     staticvoid main(string[] args)

     {

          int i =5;

          int v =40;

          int[] p =newint[4];

          try

          {

               p[i]= v;

          }

          catch(IndexOutOfRangeException e)

          {

               Console.WriteLine("Index out of bounds");

          }

          Console.WriteLine("Remaining program");

     }

}

 

 

 

a

value 40 will be assigned to a[5];

b

The output will be :
Index out of bounds
Remaining program

c

The output will be :
Remaining program

d

None of the above mentioned

correct answer b

Answer: Option (B)

112

Choose the correct output for the given set of code:

staticvoid Main(string[] args)

{

     try

     {

          Console.WriteLine("csharp"+" "+1/Convert.ToInt32(0));

     }

     catch(ArithmeticException e)

     {

          Console.WriteLine("Java");

     }

     Console.ReadLine();

}

a

csharp

b

java

c

Run time error

d

csharp 0

correct answer c

1 / 0, hence system out of flow exception error.

113

Choose the correct statement among the following which supports the fact that C# does not allow the creation of empty structures?

a

C#.NET supports creation of abstract user-defined data types using structures

b

By having empty structures,it would mean that the new data types have no data associated with, which does not make any sense in C#.NET

c

Basic reason to create structures is the inability to represent real life objects using standard data types offered by the language

d

All of the above mentioned

correct answer d

Basic definition of structures in C#.NET.

114

Which of the following is a correct statement about the C#.NET code given below?

struct book

{

     privateString name;

     privateint pages;

     private Single price;

}

book b =new book();

 

 

a

New structure can be inherited from struct book

b

When the program terminates, variable b will get garbage collected

c

The structure variable ‘b’ will be created on the stack

d

When the program terminates, variable b will get garbage collected

correct answer c

Answer: Option (C)

115

Choose the correct statement about structures as to why they are defined as value types but not reference types?

a

Since space required for structure variables is allocated on stack which is a form of memory that is automatically available when a variable to be used is in scope

b

Structures generally are used to represent user defined data types that consists of small amount of data in them.Hence using stack for declaration of such variables is not a problem.

c

All of the mentioned

d

None of the mentioned

correct answer c

Answer: Option (C)

116

Which of the following is the correct way to settle down values into the structure variable ‘e’ defined in the following code snippet?

struct emp

{

     publicString name;

     publicint age;

     public Single sal;

}

emp e =new emp();

 

 

 

a

e.name = “Ankit”;
e.age = 24;
e.sal = 200;

b

With emp e
{
.name = “Ankit”;
.age = 24;
.sal = 200;
}

c

name = “Ankit”;
age = 24;
sal = 200;

d

All of the above mentioned

correct answer a

Answer: Option (A)

117

Select the correct statements among the following?

a

A structure can contain properties

b

A structure can contain constructors

c

A structure can contain protected data members

d

A structure cannot contain constants

correct answer a,b

Answer: Option (A) and Option (B)

118

Which of the following is a correct statement about the C#.NET code given below?

class trial

{

     int i;

     float d;

}

struct sample

{

     privateint x;

     private Single y;

     private trial z;

}

sample s =new sample();

 

 

 

 

a

trial object referred by z is created on the stack

b

z is created on the heap

c

Both s and z will be created on the heap

d

s will be created on the stack

correct answer d

Answer: Option (D)

119

Choose the correct statement about structures in C#.NET?

a

Structures can be declared within a procedure

b

Structures can implement an interface but they cannot inherit from another structure

c

Structure members cannot be declared as protected

d

A structure can be empty

correct answer b,c

Answer: Option (B) and Option (C)

120

Calculate the number of bytes a structure variable s occupies in the memory if it is defined as follows.

class abc

{

     int i;

     Decimal d;

}

struct sample

{

     privateint x;

     private Single y;

     private trial z;

}

sample s =new sample();

 

 

 

 

a

24 bytes

b

8 bytes

c

16 bytes

d

12 bytes

correct answer d

Answer: Option (D)

Select a company to compare with

vs

Similar Companies