public Note(string noteName) { var letterGroups = Regex.Match(noteName, @"([^0-9]+)").Captures; var numbers = Regex.Match(noteName, @"([0-9])").Captures; if (letterGroups.Count != 1 || numbers.Count > 1) { throw new InvalidOperationException(string.Format("Note name '{0}' is invalid. " + "The name should contain a tone name and a single digit. E.g.: A, C4, F#3, Db 8", noteName)); } this.Tone = new Tone(letterGroups[0].Value); if (numbers.Count == 0) { this.Octave = new Octave(4); } else { this.Octave = new Octave(int.Parse(numbers[0].Value)); } }
public Note() { this.Tone = new Tone(); this.Octave = new Octave(); }