2

I have datarow with a few columns, some of them are string.

I want to find the row with the maximum value in a string column.

So first, Can I find a max between strings? (I need max and min for compere them and by this to find if all this column values in this datarow are equal).

I've tried things like this:

    var v = d.Max(x => x["F"]);

While d is the datarow, and "F" is the name of the string column.

If the max and min are equal, it means that the whole values are equal.

  • @TimSchmelter is right, we need to know what the string represents, and what you mean by "max" and "min"; is it a number that just happens to be read out as a string? – Clint Jun 05 '19 at 11:25
  • @TimSchmelter. That is what I've asked: For me, I don't need the max for fin the maximum, just for compere it to the minimum, and by this, to discover if the whole column's values are equal. –  Jun 05 '19 at 11:35
  • @clint. Please look at the last comment. thanks –  Jun 05 '19 at 11:36
  • I'm afraid I have, and I'm still no closer to knowing what it is you're **actually** trying to do. – Clint Jun 05 '19 at 11:36
  • Please edit the question to include more information, what is `d`? What is the value of `x["F"]`? – Clint Jun 05 '19 at 11:37
  • @clint. I am just trying to find if all of the values are equal. if the max and min are equal: that means that all the values are equal. and if the max and the min are diff: that means that there are at least 2 kinds of values. –  Jun 05 '19 at 11:41
  • I think you need to use .Max on the DataTable, not the DataRow. See https://stackoverflow.com/questions/9550836/datatable-get-max-value-using-linq-with-criteria-field-groupby – Rhys Jones Jun 05 '19 at 11:44
  • 1
    @YutiOrly yes, but what *is* the data in that string? It's a bit odd to consider the "max" of a string or a "min" of a string. Looking for the max and min will require consulting the whole row set anyway, so you might as well just use the `Distinct` function, and if you get more than one value pop out, you know not every one of them was the same, – Clint Jun 05 '19 at 11:48
  • @Clint. You're right. but I don't want to compere thw whole row, just 2 specific columns. –  Jun 05 '19 at 12:04

1 Answers1

0

Use something like this:

if (d.Where(x => x["F"].ToString() == d[0]["F"] && x["G"].ToString() == d[0]["G"]).Count() == d.Count)