|
|
|
|
|
by jebblue
3952 days ago
|
|
I'm trying my hand at getting back into some C# coding and found that apparently the language now has var. My first thought was why would a professional, statically typed language have var. Checking out the page I linked to in the submission, you can also do this cool if not slightly funky looking thing where it looks like an SQL predicate just reading from an ordinary array. |
|
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:
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.
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.