C# Programming - Structures - Discussion
Discussion Forum : Structures - General Questions (Q.No. 9)
9.
Which of the following statements are correct?
- A struct can contain properties.
- A struct can contain constructors.
- A struct can contain protected data members.
- A struct cannot contain methods.
- A struct cannot contain constants.
Discussion:
3 comments Page 1 of 1.
Suraj said:
1 decade ago
Please explain this answer.
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.
So The answer given is wrong. It should be:- 1, 2, 4, 5.
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");
}
}
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");
}
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers