What is the integer reference type in C#?

前端 未结 8 1082
日久生厌
日久生厌 2021-01-11 12:46

I\'d like to have an integer variable which can be set to null and don\'t want to have to use the int? myVariable syntax. I tried using int and

8条回答
  •  天涯浪人
    2021-01-11 13:14

    The ? syntax makes it nullable. If you dig a bit deeper, you'll see it's just a generic object that gets used.

    If you want to do it like C++ you must use unsafe operations. Then, pointers like in C are available, but your code doesn't conform to CLR...

    For using pure .NET without pointers, the ? is the way to go.

提交回复
热议问题