How to implement IComparable to sort numerical and non-numerical string.
Firstly, I want to get the Min and Max value in the "list".
It is asking me to implement ICompareable. " At least one object must implement IComparable"
Can anyone help me? Here is my code:
// setup
string filePath1 = Directory.GetCurrentDirectory().ToLower().Replace(@"\bin\debug", string.Empty)
+ @"\SampleData\products.xml";
// load XML
var xdoc1 = XElement.Load(filePath1);
//list
var elements = xdoc1.Descendants("ProductName").OrderBy(x => x.Value);
//output
Console.WriteLine("Min- " + elements.Min().Value);
Console.WriteLine("Max- " + elements.Max().Value);
Here is my XML file:
<Products>
<ProductName>9954</ProductName>
<ProductName>987</ProductName>
<ProductName>197</ProductName>
<ProductName>56</ProductName>
<ProductName>rr45</ProductName>
<ProductName>ad4</ProductName>
<ProductName>7</ProductName>
<ProductName>69dd</ProductName>
<ProductName>69</ProductName>
<ProductName>197abc</ProductName>
</Products>