C# 枚举(enum)特性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
// Start is called before the first frame update
enum Gender
{
male, female = 8, unkonw
}
void Start()
{
print((int)Gender.male);
}

// Update is called once per frame
void Update()
{

}
}

枚举中的项实际上可以表示为从0开始的整数,当给其中一项赋值为n时,其后一项会变为n+1。