- Strict typing
- Parameters as reference (a.k.a. multiple function returns)
- Generic Functions (a.k.a. type independent logic)
- Multidimensional Arrays
- Full access to C# features*
- Unity is built with it
*Some newer features of C# are not supported because Unity compiles the code itself
First we will cover C# strict typing requirement. You may be wondering why having to declare access level and type for everything is a good thing. Not only will you need to do it when coding professionally for a back-end, but explicitly declaring types has two major benefits. The first is that it will always every be one thing, and so you can't accidentally shoot yourself in the foot at runtime. Secondly, having an explicit type will help to reduce memory costs. This is because the type is known and does not need to fluctuate.
There are two ways to pass parameters to a function by reference in C#. These are
out. The main difference between
out is that
out does not need to be declared before it is passed to the function. In either case, when a function modifies a value that is passed in by reference, that change persists outside the function. This lets one function "return" multiple values while keeping the return open for other indications.
Generic functions are awesome, if you have ever been in a situation where you are copy pasting code, but only changing the calling script, then generic functions are for you. They take the form of
public void Foo<T>(T param) and can include the statement
where T : BaseClass before the opening braces to limit what types are allowed. MSDN has some good documentation on what makes generics awesome. Then, since you know the shared base class contains the function definition, you can call the function once with the referenced script instead of having to copy paste your logic tree and change up who calls it. Remember, if you are copy pasting in code, then chances are you can do it a better way.
You may think that auto-completion within MonoDevelop is rather trivial. I did too until it started getting in the way of my coding. One perfect example is
for (var int = 0; int < right there it autocompleted
int. When this happens enough, it becomes very very frustrating. There are a number of other cases where this happens, or some variables just aren't indexed, but so far in C# I haven't run into these problems.