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:

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:

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

junior

In how many ways you can pass parameters to a method?

junior

What is the difference between string and StringBuilder in C#?

middle

What is scope of a Internal member variable of a C# class?

Bình luận

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

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