Câu hỏi phỏng vấn C#
Câu hỏi

What is enum in C#?

Câu trả lời

What is an 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#:

Definition and Syntax

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:

csharp Copy
enum DayOfWeek
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}

Underlying Data Type

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:

csharp Copy
enum Months : byte
{
    Jan = 1,
    Feb,
    Mar,
    // ...
}

Accessing Enum Values

You can access enum values using the enu...

junior

junior

Gợi ý câu hỏi phỏng vấn

senior

What interface should your data structure implement to make the Where method work?

middle

What is the difference between overloading and overriding?

senior

What is the difference between Func<string,string> and delegate ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào