C# Programming - Structures - Discussion

Discussion Forum : Structures - General Questions (Q.No. 9)
9.
Which of the following statements are correct?
  1. A struct can contain properties.
  2. A struct can contain constructors.
  3. A struct can contain protected data members.
  4. A struct cannot contain methods.
  5. A struct cannot contain constants.
1, 2
3, 4
1, 2, 4
3, 5
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
3 comments Page 1 of 1.

Devendra said:   6 years ago
Completely wrong answer.

I agree with @Chinmay

Have a look in below code,

struct Employee
{
const int constValue = 10; // const value
public Employee(int val) // constructor
{

}
public int GetValue() // Method
{
return 10;
}
public void PrintName()
{
Console.WriteLine("Your name");
}
}

Chinmay said:   1 decade ago
Structures can also contain constants, fields, methods, indexers, operators, events, and nested types.

So The answer given is wrong. It should be:- 1, 2, 4, 5.

Suraj said:   1 decade ago
Please explain this answer.

Post your comments here:

Your comments will be displayed after verification.