When is using the C# ref keyword ever a good idea?

后端 未结 10 963
情歌与酒
情歌与酒 2020-11-29 06:05

The more I see ref used in production code, the more misuse I encounter and the more pain it causes me. I have come to hate this keyword, because from a framework-building s

10条回答
  •  醉话见心
    2020-11-29 06:19

    Any time you want to change the value of a value type - this happens a lot in cases where you want to efficiently update a pair of related values (i.e. rather than returning a struct containing two ints, you pass (ref int x, ref int y))

提交回复
热议问题