C# Finding the maximum value of a string with linq

前端 未结 3 1179
你的背包
你的背包 2020-12-21 15:46

This is what I have and it keeps returning null.

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

var maxTopID = (from max in         


        
3条回答
  •  悲哀的现实
    2020-12-21 16:32

    I think you are saying that TopicID is string and you want to convert it to int

    var list= (from max in dbcontext.Topics.Local
                         where  max.TopicId != null
                         select max.TopicID).ToList();
    
    int max=0;
    
    if (list.Count() !=0)
    max=list.Select(int.Parse).ToList().Max();
    

    max will contain max value from list which is converted to list of integer

提交回复
热议问题