Fixed Statement in C#

后端 未结 5 1890
南笙
南笙 2021-01-17 11:51

We have similar code to the following in one of our projects. Can anyone explain (in simple English) why the fixed statement is needed here?

class TestClass
         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-17 12:24

    It fixes the pointer in memory. Garbage collected languages have the freedom to move objects around memory for efficiency. This is all transparent to the programmer because they don't really use pointers in "normal" CLR code. However, when you do require pointers, then you need to fix it in memory if you want to work with them.

提交回复
热议问题