angle-v8.png

Benefits of C#

There are quite a few benefits to using C#, we won’t list every single one of them but we will cover the most notable benefits.

1. Strict Typing
Variables have to be declared with a datatype using C#, so if you create a variable called health which will contain the characters health it will have to be given a datatype (for example an integer for a whole number). If you declare a variable as an integer you will not be able to insert anything other than integer numbers into the variable.

This also translates to methods (functions), when you declare a method you will need to specify the datatype of any variables that are being passed to it along with the datatype for any data that is returned from it.

Experienced developers will see an immediate benefit here. Games are complicated animals, more complex than most applications and definitely a lot more complex than websites (where loose languages like JavaScript and PHP are frequently used). One of the pitfalls of using UnityScript; a loosely defined language, is that you can introduce problems down the line resultant of casting issues and mistakes. It can also lead to code that is more difficult to debug.


2. It is Object Orientated
C# is an object orientated language, so scripts automatically have an OO structure, they are clearly defined and follow convention. While this may make them more complicated, particularly for beginners or those who have avoided OOP in the past, it should be remembered that games development was one of the major proponents that lead to OO concepts being designed and adopted. Also OO concepts fit games particularly well.


3. Private by default
All methods and variables are private by default, unless you specify otherwise. This is in contrast to UnityScript where all variables are public unless specified otherwise; while public by default makes life easier for the programmer as they do not have to worry as much about the scope and access permissions of their variables, this benefit is in itself a drawback as it can introduce problems down the line.

Therefore C#’s approach of private by default leads to code that is stricter and less prone to issues and human error.


4. Advanced features and .NET Framework support
UnityScript is a custom language built for Unity, based on JavaScript, C# however is “true C#”, meaning you gain access to the advanced features that C# has to offer along with full access to the .NET Framework. This also means that you are not restricted to functions that Unity supports and can go beyond Unity.


5. Structure
C# code while more complicated than UnityScript is structurally more organized, due to points 1, 2 and 3 it is more defined and to a professional programmer, clearer. There are also smaller nuances such as class names having to match the name of the script.



There are other benefits, but these are the most cited and most impacting as together they lead to a language that is structured, organized, efficient and powerful (due to the .NET framework).

 

Article from here

Danyal MalikBenefits of C#
Share this post

Join the conversation

Related Posts