11,568 questions
If you replace your last line with this it should work:
collist = collist.OrderBy(i => sortOrderList.IndexOf(i)).ToList();
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
HI, I am trying to custom sort a list. New to c# coding. But here is the code. collist in the very end is throwing an error saying string does not contain a definition for 'codevlaue'. I am trying to sort my 'collist' according to the 'sortOrderList'. Need help with the code. Thanks in advance.
Stream responseStream = response.GetResponseStream();
string responseStr = new StreamReader(responseStream).ReadToEnd();
Console.WriteLine(responseStr);
//return responseStr;
XDocument doc = XDocument.Parse(responseStr);
var result = doc.Descendants("QUERY_DATA");
List<string> collist = new List<string>();
foreach (var item in result)
{
var atts = item.Attributes();
foreach (var att in atts)
{
collist.Add(att.Name.ToString());
}
}
collist = collist.Distinct().ToList();
if (QryName == "AdvanceDetailRpt")
{
List<string> sortOrderList = new List<string>()
{
"ClientLoanNum",
"CWLLoanNum",
"BorlastName",
"LineType",
"RequestWireAmt",
"RequestType",
"LoanAmt",
"OrigAdvAmt",
"AdvanceAmt",
"AdvanceDt",
"Tranche",
"AdjustmentRsn",
"OverUnderPosting",
"ClosingAgent",
"ABANum",
"AcctNum",
"DraftNum",
"FedRefNum",
"CashierCheckFedExTrackNum"
};
collist = collist.OrderBy(i => sortOrderList.IndexOf(i.CodeValue));
}
If you replace your last line with this it should work:
collist = collist.OrderBy(i => sortOrderList.IndexOf(i)).ToList();
CodeValue does not exists as sortOrderList is a List of string thus there are no property for CodeValue. You need to pass in a string value instead.