Код: Выделить всё
// My actual class couples observers and observables, but I didn't want to overcomplicate this question.
public class MyClass
{
private HashSet mySet = new();
private HashSet myOtherSet = new();
private Dictionary myDictionary = new();
/// Thrown when was already added to other.
public bool Add(int value)
{
// Return false if the value is already present.
if (!mySet.Add(value))
{
return false;
}
foreach (var other in myOtherSet)
{
// Use Dictionary.Add method to ensure that an exception is thrown if the key already existed,
// even though we never expect this to occur.
myDictionary.Add((value, other), value + other);
}
return true;
}
}
Не удалось найти четкое описание ответ в документации.
Подробнее здесь: https://stackoverflow.com/questions/791 ... ever-occur