Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 7-May-14 20:07pm
v3
Comments
Karen Mitchelle 8-May-14 2:08am    
Can you please elaborate further? What string are you going to get? Can you give me the scenario?
Torakami 8-May-14 2:11am    
I am in linq
Torakami 8-May-14 2:12am    
var lstrating = (from r in _db.ABC
where r.CompanyId == companyId
select new ABC
{
RatingType = r.RatingValue == null ? r.RatingValue : "N/A" + "-" + r.RatingType,
RatingValue = r.Id
}
).ToList();

1 solution

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.
 
Share this answer
 
Comments
Torakami 8-May-14 2:26am    
Thanks man , its worked with the same condition , i use tostring method

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900