本文介绍了如何比较LINQ查询中的字符串列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从数据表中检索一组"TOP n"行,其中表行按列X"排序,但前提是一行的列X"值大于提供的比较价值.这是我到目前为止的内容:

I need to retrieve a set of "TOP n" number of rows from a DataTable where the table rows are Ordered By "Column X", but only if value of "Column X" for a row is greater than a provided comparison value. This is what I have so far:

EnumerableRowCollection query = from history in dt.AsEnumerable()
                                where history.Field<string>("Column X") > "Value-To-Compare")
                                orderby history.Field("Column X")
                                select history;

但是我一直在获取不能将运算符'>'应用于类型为'string'和'string'的操作数"

But I keep on getting "Operator '>' cannot be applied to operands of type 'string' and 'string'"

有什么想法吗?

fuzzlog

推荐答案

这项工作可行吗?

EnumerableRowCollection query = from history in dt.AsEnumerable()
                                where String.Compare(history.Field<string>("Column X"), "Value-To-Compare") > 0
                                orderby history.Field("Column X")
                                select history;

这篇关于如何比较LINQ查询中的字符串列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 08:49