Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who is the greatest among all strings?

I'm inserting a special (summary) row into a DataTable, and I want it to appear last in a sorted DataView. I know the DataView is being sorted (ascending) by a particular string column, and for display purposes it doesn't matter what value appears in that column of the summary row.

What string can I place in that field to make sure my summary row gets sorted to the very end? For columns of nearly any other datatype, I could use T.MaxValue, but there unfortunately is no System.String.MaxValue constant.

I already tried

footerRow[colGrouping] = "\uFFFF";

but that sorted to the top! (DataView sorting is lexicographical, not based on numeric value of the codepoint)

like image 663
Ben Voigt Avatar asked Nov 08 '22 06:11

Ben Voigt


1 Answers

If I were to wing it without understanding lexicographical ordering I would say \uFF70

var table = new DataTable("table");
table.Columns.Add("column");

for (int i = 0; i < 65536; i++)
{
    var row = table.NewRow();
    row["column"] = (char)i;
    table.Rows.Add(row);
}

var view = new DataView(table);
view.Sort = "column";
var last = ((string)view[65535]["column"])[0];
//last is 0xff70 'ー'    
like image 133
Weyland Yutani Avatar answered Nov 23 '22 08:11

Weyland Yutani