https://learn.microsoft.com/zh-cn/dotnet/csharp/fundamentals/functional/pattern-matching
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| using JetBrains.Annotations; using UnityEngine; using UnityEngine.UI;
public class 模式 : MonoBehaviour { private InputField _inputField; [CanBeNull] private string atg; [CanBeNull] private static string Classify(int? @int) => @int switch { 1 => "Just 1", 2 => "Just 2", 3 or 4 => "3/4", null => "null", _ => "Just this" };
private void Start() { _inputField = GetComponent<InputField>(); print(Classify(int.Parse(_inputField.text))); print(atg is not null ? "atg is not null" : "atg is null"); } }
|