AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 121 - 130 of 174 questions

121

When does a structure variable get destroyed?

a

When no reference refers to it,it will get garbage collected

b

Depends on whether it is created using new or without new operator

c

As variable goes out of the scope

d

Depends on either we free its memory using free() or delete()

correct answer c

Answer: Option (C)

122

Which of the following is the correct output for the C#.NET program code given below?

{

     struct abc

     {

           publicint i;

     }

     class Program

     {

          staticvoid Main(string[] args)

          {

               sample a =new sample();

               a.i=10;

               fun(ref a);

               Console.WriteLine(a.i);

          }

          publicstatic voidn fun(ref sample x)

          {

               x.i=20;

               Console.WriteLine(x.i);

          }

     }

}

 

 

 

a

10

10

b

20

10

c

10

20

 

d

20

20

correct answer d

Output – 20
20

123

Where the properties can be declared?

a

Class

b

Struct

c

Interface

d

Namespace

correct answer a,b,c

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

124

Choose the statements which makes use of essential properties rather than making data member public in C#.NET?

a

Properties have their own access levels like private, public, protected etc. which allows it to have better control about managing read and write properties

b

Properties give us control about what values may be assigned to a member variables of a class they represent

c

Properties consist of set accessor inside which we can validate the value before assigning it to the data variable

d

All of the above mentioned

correct answer d

Answer: Option (D)

125

Select the modifiers which can be used with the properties?

a

Private

b

Public

c

Protected Internal

d

Protected

correct answer a,b,c,d

Answer: Options (A), (B), (C) and (D)

126

Choose the correct statement about the properties used in C#.NET?

a

Each property consists of accessor as get and set

b

A property can be either read or write only

c

Properties can be used to store and retrieve values to and from the data members of a class

d

Properties are like actual methods which work like data members

correct answer c,d

Answer: Option (C) and Option (D)

127

Choose the correct statements about write-only properties in C#.NET?

a

Properties which can only be set

b

Properties once set and hence values cannot be read back in nature

c

Useful for usage in classes which store sensitive information like password of a user

d

None of the above mentioned

correct answer a,b,c

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

128

Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the code below to work.Which is the correct solution to ensure this functionality?
b.maths = 10;
Console.WriteLine(b.maths);

a

Declare maths property with get and set accessors

b

Declare maths property with only get accessors

c

Declare maths property with only set accessors

d

Declare maths property with only get, set and normal accessors

correct answer a

Answer: Option (A)

129

Consider a class maths and we had a property called as sum.b which is the reference to a maths object and we want the statement Console.WriteLine(b.sum)to fail.Which among the following is the correct solution to ensure this functionality?

a

Declares sum property with only get accessor

b

Declares sum property with only set accessor

c

Declares sum property with both set and get accessor

d

Declares sum property with both set, get and normal accessor

correct answer b

Answer: Option (B)

130

If math class had add property with get and set accessors, then which of the following statements will work correctly?

 

a

math.add = 20;

b

math m = new math();
m.add = 10;

c

Console.WriteLine(math.add);

d

math m = new math();
m.add = m.add + 20;

correct answer b,d

Answer: Option (B) and (D)

Select a company to compare with

vs

Similar Companies