Is there pointer in C# like C++? Is it safe?

后端 未结 5 1536
抹茶落季
抹茶落季 2020-12-08 18:20

I\'m writing an application that work with a tree data structure. I\'ve written it with C++, now i want to write it by C#. I use pointers for implementing the tree data stru

5条回答
  •  清歌不尽
    2020-12-08 19:02

    There is a great series of Data Structures implemented in .Net 2 on MSDN.

    Data Structures Part 1

    They include sample code for things like Binary Search Tree, Graph, SkipList, NodeList, etc. The code is quite complete and includes a number of pages of docs about why these structures work, etc.

    None of the ones from Microsoft use pointers. In general you never NEED to use them in C#. There are times when using them would be nice, or they are just the way you think from C++. But you can usually find a way not to use them.

    The biggest reasons why not to use unsafe code for pointers is that you lose Medium Trust compliance. You can't run through mechanisms like click once, asp.net websites, and Silverlight doesn't allow them either. Stick with refs and fully managed concepts to ensure your code can run in more places.

提交回复
热议问题