Why would one ever use the “in” parameter modifier in C#?

后端 未结 5 1959
走了就别回头了
走了就别回头了 2020-12-02 11:08

So, I (think I) understand what the in parameter modifier does. But what it does appears to be quite redundant.

Usually, I\'d think tha

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 11:29

    There is. When passing a struct, the in keyword allows an optimization where the compiler only needs to pass a pointer, without the risk of the method changing the content. The last is critical — it avoids a copy operation. On large structs this can make a world of difference.

提交回复
热议问题