如果整数值为null,如何获取字符串 [英] How to get the string if integer value is null
本文介绍了如果整数值为null,如何获取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hii,
// RatingType = r.RatingValue == null? r.RatingValue:N / A+ - + r.RatingType,
我正在尝试这样做...其中我的r.ratingvalue是整数,如果它的null我想做这样的事情...但由于整数,它说无法将int转换为字符串
我在linq
Hii ,
//RatingType = r.RatingValue == null ? r.RatingValue : "N/A" + "-" + r.RatingType,
I am trying to do this ... in which my r.ratingvalue is integer if its null i want to do something like this ... but due to integer its saying unable to convert int to string
I am in linq
推荐答案
哦不,你的代码或想法中还有一些错误。
如果RatingValue属性是整数,它不能为空。只有它是Nullable Integer(int?)它才能为null,然后你也可以查询它的HasValue属性。
如果你需要从int获取一个字符串,只需调用ToString( ) 方法;在可以为null的int的情况下,在其Value属性上调用ToString方法。
Oh no, there are some more bugs in your code or your thoughts.
If the RatingValue property is an Integer, it cannot be null. Only if it is a Nullable Integer (int?) it can be null, and then you could also query its HasValue property.
If you need to get a string from an int, just call the ToString() method; in case of a nullable int, call the ToString method on its Value property.
这篇关于如果整数值为null,如何获取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文