title: Is it possible to create a variant value type?
body: <p>The paper <a href="http://www.two-sdg.demon.co.uk/curbralan/papers/ValuedConversions.pdf" rel="nofollow">Valued Conversions</a> by Kevlin Henney gives a motivation for a so-called variant value type functionality, as well as an outline of a C++ implementation. It is a good read and it covers exactly what I would like to have available in C#: a general type that can hold values of different <a href="http://www.boost.org/doc/libs/1_55_0/doc/html/any/reference.html#any.ValueType" rel="nofollow">value-types</a>.</p>
  
  <p>I have not been able to find anything like this in C# though. Somewhat similar questions on SO have unsatisfactory answers and comments like "this is probably not what you want". This surprises me because it looks like fairly commonly required functionality. Henney's C++ <a href="http://www.boost.org/doc/libs/1_55_0/doc/html/any.html" rel="nofollow">boost::any</a> class is widely used.</p>
  
  <p>Is it not possible to create this functionality in C#?</p>
  
  <hr>
  
  <p>Edit: Responding to one of the answers, I do not think that generics will do the trick. Using a generic requires the developer to know what kind of value-type the <code>Variant</code> variable is holding, and that type becomes immutable for that particular <code>Variant</code> variable as well. But the <code>Variant</code> type I am talking about should be able to hold different types. For example, a function <code>Variant ReadValue()</code> could read an entry from a file, parse it, fill the <code>Variant</code> value accordingly and then return it. The caller does not know in advance what kind of type will be contained in the returned <code>Variant</code>.</p>