C#使用linq查找字符串的最大值 [英] C# Finding the maximum value of a string with linq

查看:981
本文介绍了C#使用linq查找字符串的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的,并且一直返回null.

This is what I have and it keeps returning null.

当我添加where语句时,它无法识别Convert.toInt32

It doesn't recognize the Convert.toInt32 when I add a where statement

var maxTopID = (from max in dbcontext.Topics.Local
               select max.TopicID).Max();

推荐答案

如何在SELECT中转换TopicID并使用String.IsNullOrEmpty()删除空字符串,如:

How about converting the TopicID in SELECT and use String.IsNullOrEmpty() to remove empty string, like:

 var maxTopID = (from max in dbcontext.Topics.Local
                 where !String.IsNullOrEmpty(max.TopicID)
                 select Convert.ToInt32(max.TopicID)).Max();

请参见 演示

这篇关于C#使用linq查找字符串的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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