using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Data.DataSetExtensions;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.Globalization;
using System.Diagnostics;
using System.Collections.Concurrent;
public static void Main()
List<string> searchFor = new List<string>() { "123111117", "123456123", "12159785" };
foreach(var s in searchFor) {
Console.WriteLine(string.Format("No match for {0}", s));
Console.WriteLine( string.Format( "{0} is {1}", s, r.name ) );
public static List<Lookup> lookup =new List<Lookup>() {
public static Lookup FindMatch(string valueToSearchInLinq) {
var result = lookup.Select(x=> new {x, count = valueToSearchInLinq.StartsWith(x.code)? x.code.Length : -1})
.OrderByDescending(x=>x.count);
return result.All(x=>x.count <0)? new Lookup() : result.FirstOrDefault().x;