This may sound like a pretty dumb question, and maybe in fact it is, but I had always this clue and where never clear to get the correct answer.
In terms of performance, when you are updating/monitoring a string, what is more important, always update the string no matter if it changed, or first put an IF statement and see if the string has changed and if so, update?
Maybe its not clear, so we will take a practical example, assume we are running a thread or a timer that is checking,every 100ms the count of process, from Process.GetProcesses
Label1.Text = Process.GetProcesses.Count
Vs.
if Process.GetProcesses.Count <> Label1.Text Then
Label1.Text = Process.GetProcesses.Count
end if
Vs. (and I read that .Equals is faster
if Not Label1.Text.Equals(Process.GetProcesses.Count) Then
Label1.Text = Process.GetProcesses.Count
end if
The reason I assume that always setting the text without IF should be faster is that you are not querying the process.getprocesses.count class two times, but on the other hand, it's forcing the label to update its properties...
What are the best practices to this?