You have to declare a variable which you will then ignore. This is most commonly the case with the TryParse (or TryWhatever) pattern, when it is used to test the validity of user input (e.g. can it be parsed as a number?) without caring about the actual parsed value.
您在问题中使用了“ pose”这个词,我怀疑这只是一种不幸——但是如果 out 参数属于实现 IDisposable 的类型,那么您当然应该调用 Dispose,除非方法文档明确指出接收值并不意味着所有权。但是我不记得曾经看到过使用一次性 out参数的方法,所以我希望这只是一个不幸的选择。
public void PrintCoordinates(Point p)
{
p.GetCoordinates(out int x, out int y);
WriteLine($"({x}, {y})");
}
public void PrintXCoordinate(Point p)
{
p.GetCoordinates(out int x, out _); // I only care about x
WriteLine($"{x}");
}
//Remove item from list and ignore reference to removed item
public static void TryRemoveIgnore<K,T>(this ConcurrentDictionary<K,T> dictionary, K key)
{
T CompletelyIgnored;
dictionary.TryRemove(key, out CompletelyIgnored);
}