C# Programming - Enumerations - Discussion
Discussion Forum : Enumerations - General Questions (Q.No. 1)
1.
Which of the following statements are correct about an enum used inC#.NET?
- By default the first enumerator has the value equal to the number of elements present in the list.
- The value of each successive enumerator is decreased by 1.
- An enumerator contains white space in its name.
- A variable cannot be assigned to an enum element.
- Values of enum elements cannot be populated from a database.
Discussion:
2 comments Page 1 of 1.
Nicholas Mahbouby said:
1 decade ago
In your example you are changing the value of your instance of Volume. Answer 4 was referring to an individual element within the enum declaration.
For example the following declaration would be illegal.
public enum Volume
{
Low = x,
Medium = y,
High = z
}
For example the following declaration would be illegal.
public enum Volume
{
Low = x,
Medium = y,
High = z
}
Raja ashutosh nayak said:
1 decade ago
The value of variable can be assign to a enum variable for that you need to type cast the variable to enum type.
public enum Volume : byte
{
Low = 1,
Medium,
High
}
string volString = Console.ReadLine();
int volInt = Int32.Parse(volString);
Volume myVolume = (Volume)volInt;
public enum Volume : byte
{
Low = 1,
Medium,
High
}
string volString = Console.ReadLine();
int volInt = Int32.Parse(volString);
Volume myVolume = (Volume)volInt;
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers