I came across a situation where my overridden method ToString()would use one of the collection of instances.
public override string ToString()
{
string returnStr = "testString";
lock (_sync)
{
returnStr = $"{returnStr}: {string.Join(",", _testList)}";
}
return returnStr;
}
Since we are talking about a multi-threaded application, I was interested, since I would have to use the lock()method inside the body ToString()to avoid modifying the collection while my return string is generated. While I am making changes to the collection, the same object ( _sync) is blocked, of course.
But this method is used by other processes, such as Visual Studio Debugger, and who knows what else, since this method is inherited from the class itself Object.
For example: . I am afraid that this may be caused most often behind the scenes (frame or something else) and he will have to use a lock (which can lead to loss of performance), or it may cause a dead end while I am debugging a bad moment.
:
, ToString() ( .net)?
?
. , ( , ), , ToString(). , , string.Join() ToString(), .
!