using System.Collections.Generic;
public static void Main()
const string DEFAULT = "default";
IList<ReportFilenameFormat> formatList = new List<ReportFilenameFormat>()
{new ReportFilenameFormat()
{Name = "a", OrganizationCode = "A"}, new ReportFilenameFormat()
{Name = "b", OrganizationCode = "B"}, new ReportFilenameFormat()
{Name = "c", OrganizationCode = "Default"}, new ReportFilenameFormat()
{Name = "d", OrganizationCode = "Something"}, new ReportFilenameFormat()
{Name = "e", OrganizationCode = "other"}};
string reportOrgCode = "z";
ReportFilenameFormat selectedOrg = formatList.Where(x => x.OrganizationCode.ToLower() == reportOrgCode).FirstOrDefault();
if ((selectedOrg == null))
selectedOrg = formatList.Where(x => x.OrganizationCode.ToLower() == DEFAULT).FirstOrDefault();
Console.WriteLine(string.Format("Original logic {0} : {1}", selectedOrg.Name, selectedOrg.OrganizationCode));
.Where(x => (x.OrganizationCode.ToLower() == reportOrgCode || x.OrganizationCode.ToLower() == DEFAULT ))
.OrderBy(x => (x.OrganizationCode == DEFAULT ? 99 : 1 ) ).FirstOrDefault();
Console.WriteLine(string.Format("LINQ logic {0} : {1}", selectedOrg.Name, selectedOrg.OrganizationCode));
public class ReportFilenameFormat
public string Name { get; set; }
public string OrganizationCode { get; set; }