Skip to content

Instantly share code, notes, and snippets.

@daleth90
Created Nov 26, 2018
Embed
What would you like to do?
using System;
enum Season { SPRING = 1, SUMMER, AUTUMN = 5, WINTER }
class Program {
static void Main() {
Console.WriteLine( (Season)1 ); // SPRING
Console.WriteLine( (Season)2 ); // SUMMER
Console.WriteLine( (Season)5 ); // AUTUMN
Console.WriteLine( (Season)6 ); // WINTER
// 10 並不在 Season 設定的數值內,因此雖然轉型能夠成功,但會直接印出 10
Console.WriteLine( (Season)10 ); // 10
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment