Answers for "static dictionary c#"

C#
2

static dictionary c#

/// <summary>
/// Contains plural logic in static class [separate file]
/// </summary>
static class PluralStatic
{
    /// <summary>
    /// Static string Dictionary example
    /// </summary>
    static Dictionary<string, string> _dict = new Dictionary<string, string>
    {
        {"entry", "entries"},
        {"image", "images"},
        {"view", "views"},
        {"file", "files"},
        {"result", "results"},
        {"word", "words"},
        {"definition", "definitions"},
        {"item", "items"},
        {"megabyte", "megabytes"},
        {"game", "games"}
    };

    /// <summary>
    /// Access the Dictionary from external sources
    /// </summary>
    public static string GetPlural(string word)
    {
        // Try to get the result in the static Dictionary
        string result;
        if (_dict.TryGetValue(word, out result))
        {
            return result;
        }
        else
        {
            return null;
        }
    }
}
Posted by: Guest on September-02-2020

C# Answers by Framework

Browse Popular Code Answers by Language