π Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
π Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
1. What is an enum in C#?
Answer:
Explanation:
An enum (enumeration) in C# is a value type defined by a set of named integral constants.
2. What is the default underlying type of an enum in C#?
Answer:
Explanation:
In C#, the default underlying type of an enum is 'int'.
3. How can you define an enum in C# with a different underlying type?
Answer:
Explanation:
The underlying type of an enum can be specified after the colon in the enum declaration.
4. Can an enum in C# contain duplicate values?
Answer:
Explanation:
Enums in C# cannot contain duplicate values. Each value in an enum must be unique.
5. How do you assign a specific value to an enum member in C#?
Answer:
Explanation:
Specific values can be assigned to enum members by using the equals sign followed by the value.
6. What is the first value of an enum in C# if no value is explicitly assigned?
Answer:
Explanation:
If no value is explicitly assigned to the first member of an enum, its value defaults to 0.
7. How can you convert an enum to its corresponding numeric value?
Answer:
Explanation:
An enum can be cast to its underlying type or converted using the Convert class.
8. How do you define a flag enum in C#?
Answer:
Explanation:
A flag enum is defined by applying the [Flags] attribute and usually assigning values as powers of two.
9. Can you use strings as enum values in C#?
Answer:
Explanation:
Enums in C# must be integral types; string values are not allowed.
10. What happens when you try to parse an invalid string to an enum in C#?
Answer:
Explanation:
Attempting to parse an invalid string to an enum using Enum.Parse will result in a runtime exception.
Comments
Post a Comment
Leave Comment