2023-06-19 Unity Advanced C# Knowledge Supplement 2 - Relationship between C# Version and Unity

1. Unity and C# version

Unity version C# version
Unity 2021.2 C# 9
Unity 2020.3 C# 8
Unity 2019.4 C# 7.3
Unity 2017 C# 6
Unity 5.5 C# 4

​ More information can be viewed on the official website of Unity: Unity - Manual: C# compiler (unity3d.com)

​ The reason why different versions of Unity support different versions of C# is that the versions of C# compiler and script runtime used by different versions of Unity are different.

​ For example: The script runtime version used by Unity 2020.3 is equivalent to .Net 4.6, and the compiler is Roslyn (Roslyn compiler).
​ So with the update of Unity, a newer compiler and runtime version will generally be adopted.
​ The new version of the scripting runtime will bring a large number of new C# features and .NET features to Unity, which means that it can support higher versions of C#.

​ We can judge whether we can use some new features in each version of C# for programming according to the corresponding C# versions supported by different Unity.
​ Although we can develop normally without mastering these functions, often new functions allow us to write simpler and clearer codes and save the amount of code.

2. Unity's .Net API Compatibility Level

​ The compatibility level of the .Net API can be set in PlayerSetting ->Other Setting ->Api Compatibility Level:

image-20230619134919644
  • .Net 4.x (on special request):
    • It has a relatively complete .Net API, and even includes some APIs that cannot be cross-platform.
    • Mainly for the Windows platform, and will use the features not in .Net Standard 2.0, it will be chosen to use it.
  • .Net Standard 2.0 (recommended):
    • It is a set of .Net standard APIs, which contains less content than .Net 4.x, which can reduce the final executable file size.
    • Has better cross-platform support.
    • .Net Standard 2.0 configuration files are half the size of .Net 4.x configuration files

​Normally , use .Net Standard 2.0 .

Guess you like

Origin blog.csdn.net/zheliku/article/details/131286325