public void AddOrUpdateWeight(T1 value, float weight) { if (weight == 0) { throw new ArgumentException("weighted value cannot have a 0% chance."); } WeightedChance <T1> existing = this._weights.FirstOrDefault(x => Object.Equals(x.Value, value)); if (existing == null) { var instance = new T2 { Value = value, Weight = weight }; this._weights.Add(instance); } else { existing.Weight = weight; } this._adjusted = false; }
public void RemoveWeight(T value) { WeightedChance <T> existing = this.weights.FirstOrDefault(x => Object.Equals(x.Value, value)); if (existing != null) { this.weights.Remove(existing); this.adjusted = false; } }