使非可空值类型为可空 [英] Making a Non-nullable value type nullable

查看:98
本文介绍了使非可空值类型为可空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用受限的简单结构。该结构是在从数据库调用数据的方法中创建的。如果没有从数据库返回的数据,我希望能够返回空值,但是Visual Studio抱怨说,无法将空值转换为PackageName.StructName,因为它是非空值类型。

I have a simple struct that has limited use. The struct is created in a method that calls the data from the database. If there is no data returned from the database I want to be able to return a null, but Visual Studio complains, Cannot convert null to PackageName.StructName because it is a non-nullable value type.

如何使其可为空?

推荐答案

您要查看 Nullable< T> 值类型。

You want to look into the Nullable<T> value type.

这篇关于使非可空值类型为可空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆