Should you use pointers (unsafe code) in C#?

后端 未结 11 2455
既然无缘
既然无缘 2020-12-05 02:15

Should you use pointers in your C# code? What are the benefits? Is it recommend by The Man (Microsoft)?

11条回答
  •  攒了一身酷
    2020-12-05 02:45

    I can't remember ever having to do so - but I haven't done much interop. That's the most common application, I believe: calling into native code. There are a very few times where using pointers allows you to optimise some code, but it's pretty rare in my experience.

    If it's any guide, I consider myself to be pretty experienced in C# but if I had to do any unsafe code I'd have to consult the spec/books/MSDN to guide me. Of course there will be plenty of people who are happy with unsafe code but less familiar with (say) query expressions...

提交回复
热议问题