convert int to nullable int?

前端 未结 6 790
北恋
北恋 2020-12-15 04:43

I need to know how to convert an int to a nullable int. However, I keep getting an error \"The binary operator Equal is not defined for the types \'System.Nullable`1[System.

6条回答
  •  半阙折子戏
    2020-12-15 05:31

    Typically, you convert an int an int? using a cast.

    int? myNullable = (int?) 15;
    int myInt = (int) myNullable;
    

提交回复
热议问题