티스토리 뷰
728x90
반응형
enum Season
{
Spring,
Summer,
Autumn,
Winter
}
enum ErrorCode : ushort
{
None = 0,
Unknown = 1,
ConnectionLost = 100,
OutlierReading = 200
}
enum 과 switch 문 활용 예)
public enum WhiteIpRequestState
{
NoRequest = 0,
Requested = 1,
Approved = 2,
Rejected = 3
}
WhiteIpRequestState whiteIpRequestState = ...
switch(whiteIpRequestState)
{
case WhiteIpRequestState.NoRequest:
case WhiteIpRequestState.Rejected:
return RedirectToAction("WhiteIpRequest", "Login");
case WhiteIpRequestState.Requested:
return RedirectToAction("WhiteIpRequestInProcess", "Login");
default:
break;
}
[Flags]
public enum Days
{
None = 0b_0000_0000, // 0
Monday = 0b_0000_0001, // 1
Tuesday = 0b_0000_0010, // 2
Wednesday = 0b_0000_0100, // 4
Thursday = 0b_0000_1000, // 8
Friday = 0b_0001_0000, // 16
Saturday = 0b_0010_0000, // 32
Sunday = 0b_0100_0000, // 64
Weekend = Saturday | Sunday
}
public class FlagsEnumExample
{
public static void Main()
{
Days meetingDays = Days.Monday | Days.Wednesday | Days.Friday;
Console.WriteLine(meetingDays);
// Output:
// Monday, Wednesday, Friday
Days workingFromHomeDays = Days.Thursday | Days.Friday;
Console.WriteLine($"Join a meeting by phone on {meetingDays & workingFromHomeDays}");
// Output:
// Join a meeting by phone on Friday
bool isMeetingOnTuesday = (meetingDays & Days.Tuesday) == Days.Tuesday;
Console.WriteLine($"Is there a meeting on Tuesday: {isMeetingOnTuesday}");
// Output:
// Is there a meeting on Tuesday: False
var a = (Days)37;
Console.WriteLine(a);
// Output:
// Monday, Wednesday, Saturday
}
}
public enum Season
{
Spring,
Summer,
Autumn,
Winter
}
public class EnumConversionExample
{
public static void Main()
{
Season a = Season.Autumn;
Console.WriteLine($"Integral value of {a} is {(int)a}"); // output: Integral value of Autumn is 2
var b = (Season)1;
Console.WriteLine(b); // output: Summer
var c = (Season)4;
Console.WriteLine(c); // output: 4
}
}
An enumeration type (or enum type) is a value type defined by a set of named constants of the underlying integral numeric type. To define an enumeration type, use the enum keyword and specify the names of enum members:
728x90
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- React
- 상품 등록
- 스프링 시큐리티(spring security)-http basic 인증
- MainActor
- 스프링 프레임워크(spring framewordk)
- java-개발 환경 설정하기
- REST API
- jstl(java standard tag library)-core
- jsp 오픈 소스
- 특정 문자를 기준으로 자르기
- 제품 등록
- System.Diagnostics
- java 키워드 정리
- await
- 메이븐(maven)
- 스프링 프레임워크(spring framework)
- 람다식(lambda expression)
- jstl(java standard tag library)
- java web-mvc
- 스프링 시큐리티(spring security)
- 표현 언어(expression language)
- 문자 자르기
- 진수 변환
- .submit()
- nl2br
- 인텔리제이(intellij)
- java.sql
- In App Purchase
- error-java
- system.io
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함