public string DecodeNumber(int num) { List <KeyValuePair <int, string> > markers = new Dictionary <int, string> { { HelperStrategy.BYTENUMBER, HelperStrategy.BYTELETTERS }, { HelperStrategy.BITNUMBER, HelperStrategy.BITLETTERS } } .OrderBy(kv => kv.Key).ToList(); // var names = markers.Where(kv => num % kv.Key == 0).Select(kv => kv.Value); var names = markers.Where(kv => HelperStrategy.IsMatch2(num, kv.Key)).Select(kv => kv.Value); return(names.Any() ? string.Join(string.Empty, names) : num.ToString()); }
public string DecodeNumber(int num) { // Arrays of anonymous type new { integer Number, string Name } var markers = new[] { new { Number = HelperStrategy.BITBYTENUMBER, Name = HelperStrategy.BITBYTELETTERS }, new { Number = HelperStrategy.BITNUMBER, Name = HelperStrategy.BITLETTERS }, new { Number = HelperStrategy.BYTENUMBER, Name = HelperStrategy.BYTELETTERS } }; // var names = markers.Where(kv => num % kv.Key == 0).Select(kv => kv.Value); var names = markers.Where(kv => HelperStrategy.IsMatch2(num, kv.Number)).Select(kv => kv.Name); return(names.Any() ? names.FirstOrDefault() : num.ToString()); }