private void OnDestroy() { if (Instance == this) { Instance = null; } }
private void Awake() { if (Instance != null) { Debug.LogWarning("Already a CharacterDict in scene! Deleting myself!"); Destroy(this); return; } Instance = this; }
private void btnCaclulateCounts_Click(object sender, EventArgs e) { CharacterDict.Clear(); try { UserContent = txtCharacterEntry.Text.ToCharArray(0, txtCharacterEntry.Text.Length); if (UserContent.Length > MAX_CHARACTER_CONTENT_SIZE) { throw new IndexOutOfRangeException($"Max size is {MAX_CHARACTER_CONTENT_SIZE} and you have exceeded it. Delete some characters."); } foreach (char aChar in UserContent) { if (CharacterDict.ContainsKey(aChar)) { CharacterDict[aChar]++; } else { if (aChar != '0' && String.IsNullOrWhiteSpace(aChar.ToString()) == false) { CharacterDict.Add(aChar, 1); } } } txtCharCountBreakdown.Text = ""; foreach (KeyValuePair <char, int> pair in CharacterDict) { txtCharCountBreakdown.Text += "'" + pair.Key.ToString() + "' - " + pair.Value.ToString(); txtCharCountBreakdown.Text += Environment.NewLine; } } catch (Exception ex) { MessageBox.Show("An unexpected error has occurred.\nError: " + ex.Message); } }