Method with Multiple Return Types
<p>I've looked through many questions that are similar to this, but none of them really touched on what I precisely want to do. What I am trying to do is read from an external source a list of variables that also include their data type into a string array:</p>

<p>Example: </p>

<pre><code>ID/Key      Type    Value/Data; 
varName1    bool    true;
varName2    string  str;
varName3    int     5;
</code></pre>

<p>I then store these are objects into a dictionary as objects containing several strings, with the ID also serving as the key. </p>

<p>What I want to do is now create a method that uses a switch statement that casts the string into the correct datatype, and returns it without having to specify anything in the method call. The function should look something like this: </p>

<pre><code>public ??? Method(string key)
{
    if(dictionary.ContainsKey(ID))
    {
        Var temp = dictionary[ID];

        switch (temp.Type)
        {
            case "bool":
                return Convert.ToBoolean(temp.Value);

            case "int"
                return Convert.ToInt(temp.Value);

            case "string"
                return temp.Value;
        }
    }

    return "NULL"; 
}
</code></pre>

<p>The method call should look something like this: </p>

<pre><code>int x = Method(string key);
string word = Method(string key);
bool isTrue = Method(string key);
</code></pre>

<p>Maybe I've missed something, but I have yet to find something that really does something quite like this. Any and all thoughts about this are welcome as well. </p>