Code with undefined behavior in C#

后端 未结 7 744
面向向阳花
面向向阳花 2020-12-03 06:47

In C++ there are a lot of ways that you can write code that compiles, but yields undefined behavior (Wikipedia). Is there something similar in C#? Can we write code in C# th

7条回答
  •  臣服心动
    2020-12-03 06:49

    Looking at the Wikipedia article on undefined behaviour, the situations in which undefined behavior happens are either not allowed or throw an exception in C#.

    However in Unsafe code, undefined behavior I believe is possible, as that allows you to use pointers etc.

    Edit: It looks like I'm right: http://msdn.microsoft.com/en-us/library/aa664771%28VS.71%29.aspx

    Has an example of undefined behavior in c#

提交回复
热议问题