How did I do?*

Using dictionaries in .NET

  • Find a value by a known position
var nameKey = properties.ElementAt(nameIndex).Key;
var nameExists = properties.TryGetValue(nameKey, out var name);

if (nameExists)
{
    return name;
}
  • Find a value by a known key
var nameExists = properties.TryGetValue(nameKey, out var name);

if (nameExists)
{
    return name;
}
  • Find a value by its name pattern
if (nameKey.EndsWith("NM", StringComparison.OrdinalIgnoreCase))
{
    var nameKey = properties.ElementAt(nameIndex).Key;
    var nameExists = properties.TryGetValue(nameKey, out var name);

    if (nameExists)
    {
        return name;
    }
}