Doing assignment in Break condition

2019-09-23 16:34发布

问题:

While testing something, I had to replace string (many times!) while feeling lazy to stop debugger and write up my code. Instead I thought I can do this in Break condition to see if it works.

So the break condition looks like this:

(someString = someString.Replace(".xx.", ".yy.")) != ""

Which would evaluate to true every time.

But it doesn't do the assignment. Can someone explain why the condition is evaluated correctly, but assignment never happens?

回答1:

You should do this in the Watch or Immediate windows instead. The purpose of the Break condition is to break when an expression is true, not to continuously change a real value.

It's quite a bizarre need IMHO.