I have a problem with LINQ (in C#). I need to order a list of records by a field, which should be int
, but sometimes not :
from MyObject obj in new
Do not use Int32.Parse, but use a method you create yourself that uses Int32.TryParse to try to parse the int. If it succeeds, return the number found, if it fails return Int32.MaxValue to get that at the end.
from MyObject obj in new MyObject()
where obj.Visibile=="1"
orderby TryParse(obj.Order) ascending
select obj;
public int TryParse(string value)
{
int val;
if (Int32.TryParse(value, out val))
return val;
return Int32.MaxValue;
}