What is enum in C#?
What is enum in C#?
In C#, an enum (short for enumeration) is a special data type that allows you to define a set of named constants. It is used to create a collection of related constants that can be assigned to variables or used in other parts of your code.
Here are the key points about enums in C#:
An enum is defined using the enum
keyword followed by the name of the enum and a set of named constants enclosed in curly braces {}
. For example:
enum DayOfWeek
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
By default, an enum has an underlying data type of int
, but you can specify a different integral type such as byte
, sbyte
, short
, ushort
, int
, uint
, long
, or ulong
. For example:
enum Months : byte
{
Jan = 1,
Feb,
Mar,
// ...
}
You can access enum values using the enu...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào