C# Winform | enum foreach
enum foreach
foreach (sample_t p in Enum.GetValues(typeof(sample_t)))
{
Console.WriteLine(p.ToString() + " : " + (int)p);
}
|
cs |
TEST CODE - 1
public enum sample_t
{
SAMPLE1,
SAMPLE2,
SAMPLE3,
SAMPLE4,
}
|
cs |
output
SAMPLE1 : 0
SAMPLE2 : 1
SAMPLE3 : 2
SAMPLE4 : 3
TEST CODE - 2
public enum sample_t
{
SAMPLE1 = -100,
SAMPLE2,
SAMPLE3,
SAMPLE4,
}
|
cs |
output
SAMPLE1 : -100
SAMPLE2 : -99
SAMPLE3 : -98
SAMPLE4 : -97
TEST CODE - 3
public enum sample_t
{
SAMPLE1 = 120,
SAMPLE2 = 59,
SAMPLE3 = 110,
SAMPLE4,
SAMPLE5,
SAMPLE6 = -1,
SAMPLE7,
}
|
cs |
output
SAMPLE7 : 0
SAMPLE2 : 59
SAMPLE3 : 110
SAMPLE4 : 111
SAMPLE5 : 112
SAMPLE1 : 120
SAMPLE6 : -1
'C# Winform' 카테고리의 다른 글
C# Winform | Json - Read, Write (0) | 2020.08.24 |
---|---|
C# Winform | List Sort | ObservableCollection Sort (0) | 2020.07.03 |
C# Winform | Hardware Info | CPU ID, HDD, Mac, Serial (0) | 2020.04.29 |
C# Winform | DateTime Convert(Long To, TimeStamp to) (0) | 2020.04.28 |
C# Winform | properties settings 저장 (0) | 2020.03.05 |