Is Unity’s version of C# different than what comes with Visual Studio?
Is C# that malleable that it can be interpreted in so many ways that in each program that uses it, the library is different for each program?
Is Unity’s version of C# different than what comes with Visual Studio?
Is C# that malleable that it can be interpreted in so many ways that in each program that uses it, the library is different for each program?
Yes and no. Unity doesn’t use the Microsoft C# compiler or .net framework, it uses an open source version called Mono. It is the same language, built on the same specification, just by different people.
I have no idea what the second part of your question is asking. Care to elaborate on that?
C# doesn’t “come with Visual Studio”, it’s a language that is compiled for the Microsoft .NET framework via the .NET SDK on Microsoft platforms. Though now we have .NET Core that runs on other platforms. You could write C# programs and compile them with the command line compiler from the SDK if you wanted to. No Visual Studio required.
Unity uses Mono, which is an open source implementation of .NET. That complicates things a bit to the point where in Unity 5.x we’re stuck with the equivalent of somewhere between C# 3.0 and 4.0. In Unity 2017.1, it looks like they’ll use a newer version of Mono and support C# 6.
I’m sure I’m not saying it quite right; I’m no expert on how compiling works in Unity or anything, but that’s the basic idea.
Are you saying that the wording, from “void” to “public” to… anything… can be different to get code to function between Unity and VS?
No, I’m saying the exact opposite. It’s the same language, just with a different compiler.
No. They only real differences are you can’t use some of the newer keywords and operators. Unity doesn’t support dynamic or ?. and so on. But the rest of the language is the same.
Unity does have its own API, which is part of the UnityEngine namespace. But that’s nothing to do with the language.
This isn’t how languages work.
A language is not the library.
The language defines the syntax, the library defines a set of classes that are premade for you to use. C# in Visual Studio happens to come with the Standard .net library/framework.
What is ‘.net’ can be broken up into several parts…
Languages - C#, VB.Net, J#, unityscript, and several others
Compiler - compiles the languages into:
CIL - Common Intermediate Language - this is the intermediate language that all the previous named languages actually compile into to be ran in the…
CLR - Common Language Runtime - the runtime that takes the CIL and JIT (just in time) compiles it to machine code to be ran on specific hardware in a specific OS (this is what allows it to be cross-platform).
Common .Net Framework Class Library - this is the System namespace and all the classes available in it.
3rd Party Libraries - these are extra dll’s that you can include in your project to gain access to extra libraries (like Unity’s UnityEngine.dll… hence the ‘using UnityEngind;’ at the top of your script files)
…
THEN to confuse you a little more, there is Mono.
Mono is an open-source implementation of both the CLR and the Common .Net Framework Class Library.
…
Then for more confusion, there are several versions of both the language and the framework. Language versions include new syntax (like ‘await’ and ‘lambda functions’), and framework version include new classes you can use. Sometimes language versions add syntax that taps into features of new framework versions (the ‘await’ keyword of C# 6 taps into the Task library of .Net Framework 4.0).
…
Then to confuse it yet again.
Unity uses a custom mono CLR based on an old version of mono. Meaning several features are missing. They are currently adding support for a newer version of C# in the beta, but haven’t fully included the new libraries, but will be soon (unless they have recently… I don’t have a finger on the daily pulse of that).
…
Then to confuse it yet again.
There are several sub versions of the .Net framework that offer limited portions of the framework. This way you can have more compact versions of the runtime to deploy on lower-power and embedded systems. Or more cross-platform friendly versions, such as targeting non-windows OS’s which have no need for specific sections of the main framework since they’re Windows specific (this is what the Core set of libraries is attempting to do, which recently was released by MS).
I think, to answer my question (which is apparently difficult to understand, so assume you answered it), my feelings on Unity’s scripting are correct.
I’ll just leave it at that, and thank you.