AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 1 - 10 of 11 questions

1

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)

2

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)

3

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)

4

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)

5

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)

6

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)

7

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)

8

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)

9

Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the statement b.sum = 10 to fail.Which of the follwing is the correct
solution to ensure this functionality?

a

Declare sum property with both get and set accessors

b

Declare sum property with both get and set accessors

c

Declare sum property with get, set and normal accessors

d

None of the mentioned

correct answer c

Answer: Option (C)

10

Select the correct statement about properties of read and write in C#.NET?

a

A property can simultaneously be read or write only

b

A property can be either read only or write only

c

A write only property will only have get accessor

d

A read only property will only have get accessor

correct answer b,d

Answer: Option (B) and (D)

Select a company to compare with

vs

Similar Companies