It is C#'s support for monads.
In terms of var. It's best not to think of it as dynamic like javascript. You can't do this for example:
var a = 123;
a = "Hello";
The second line will throw an exception because 'a' is not a string, it's an int. So it's not dynamic like JS. It simply infers the type when it can so that you don't have to type it, otherwise its exactly the same.Interestingly C# does have a dynamic aspect too, and that's with the 'dynamic' keyword.
dynamic x = 123;
x = "Hello";
That will work where the var example wouldn't. It's a rarely used feature, but comes in useful to avoid boilerplate when dealing with external 'stuff', like XML files, JSON, or REST responses.It might be because C++ has auto. Kind of related Java has Object.
I haven't figured out if people want languages like C++ to be a loose typed language and just be able to type cast anything to a single type. Boost does introduce the variant type - but it's usage seems very unintuitive. I kind of get what they were trying to do - but overall Boost libraries seem overly complex for what they are trying to solve.
I wrote my own variant type based on Ptype's variant [1] [2]. To me a variant shouldn't just be a container for any object - it should have some basic intelligence for built in types (like what to do when adding a string and an int - the result should be a string. Conversely - when adding an int and a string the result should be an int.).
[1] https://srchub.org/p/cppvariant/source/tree/tip/variant.h
[2] https://srchub.org/p/ptypes/source/tree/tip/src/pvariant.cxx