Is the C# compiler smart enough to optimize this code?

前端 未结 6 822
无人及你
无人及你 2020-11-27 18:22

Please ignore code readability in this question.

In terms of performance, should the following code be written like this:

int maxResults = criteria.M         


        
6条回答
  •  日久生厌
    2020-11-27 18:51

    If criteria is a class type, I doubt it would be optimized, because another thread could always change that value in the meantime. For structs I'm not sure, but my gut feeling is that it won't be optimized, but I think it wouldn't make much difference in performance in that case anyhow.

提交回复
热议问题