本文地址:https://blog.csdn.net/t163361/article/details/107266702
最近准备申请新星创作者,需要2000个粉丝关注,觉得文章有用的,请点一下左侧边栏的关注,谢谢。
Unity和.Net/C#的关系
Unity和C#版本对应关系
Unity 6 C#9
和2021.2保持一致
Unity 2023.2 C#9
和2021.2保持一致
Unity 2022.3 C#9
和2021.2保持一致
Unity 2021.2 C#9
以下功能不支持
- Suppress emitting localsinit flag
- Covariant return types
- Module Initializers
- Extensible calling conventions for unmanaged function pointers
- Init only setters
Unity 2020.2 C#8
以下功能不支持
- Default interface methods
- Indices and ranges
- Asynchronous streams
- Asynchronous disposable
Unity 2018.3 C#7.3
Unity 2018.2 C#7.2
Unity 2017.1 C#6 .Net 4.6
Unity 5.5 C#4.0
Unity对.NetCore的支持情况
第一阶段计划在2023年能够使用.NetCoreCLR来支撑Standalone运行时。
第二阶段计划在2024年把Unity编辑器也使用.Net CoreCLR,同时删除对.Net Mono的支持
信息来源unity-and-net-whats-next
Unity和C#的论坛讨论贴Unity Future .NET Development Status
C#特性
##C#13.0特性
.Net 9 支持C#13
- New escape sequence - \e:新的转义序列 - \e
- Method group natural type improvements:方法组自然类型改进
- Implicit indexer access in object initializers:对象初始值设定项中的隐式索引器访问
C#12.0特性
.Net 8 支持C#12
- Primary constructors:主构造函数
- Collection expressions:集合表达式
- Inline arrays:内联数组
- Optional parameters in lambda expressions:Lambda 表达式中的可选参数
- ref readonly parameters:ref readonly 参数
- Alias any type:任何类型的别名
- Experimental attribute:实验属性
- Interceptors:拦截器
C#11.0特性
.NET 7 支持 C#11
- Generic attributes:泛型属性
- Generic math support:泛型数学支持
- Numeric IntPtr and UIntPtr:数值 IntPtr 和 UIntPtr
- Newlines in string interpolations:字符串内插中的换行符
- List patterns:列表模式
- Improved method group conversion to delegate:改进了方法组向委托的转换
- Raw string literals:原始字符串文本
- Auto-default struct:自动默认结构
- Pattern match Span or ReadOnlySpan on a constant string:常量 string 上的模式匹配 Span 或 ReadOnlySpan
- Extended nameof scope:扩展的 nameof 范围
- UTF-8 string literals:UTF-8 字符串字面量
- Required members:必需的成员
- ref fields and ref scoped variables:ref 字段和 ref scoped 变量
- File scoped types:文件范围类型
C#10.0特性
.NET 6 支持 C# 10
- Record structs:记录结构
- Improvements of structure types:结构类型的改进
- Interpolated string handlers:内插字符串处理程序
- global using directives:global using 指令
- File-scoped namespace declaration:文件范围的命名空间声明
- Extended property patterns:扩展属性模式
- Improvements on lambda expressions:对 Lambda 表达式的改进
- Allow const interpolated strings:可使用 const 内插字符串
- Record types can seal ToString():记录类型可密封 ToString()
- Improved definite assignment:改进型明确赋值
- Allow both assignment and declaration in the same deconstruction:在同一析构中可同时进行赋值和声明
- Allow AsyncMethodBuilder attribute on methods:可在方法上使用 AsyncMethodBuilder 属性
- CallerArgumentExpression attribute:CallerArgumentExpression 属性
- Enhanced #line pragma:增强的 #line pragma
C#9.0新特性
.Net5支持C#9.0
- Records:记录
- Init only setters:仅限 Init 的资源库
- Top-level statements:顶级语句
- Pattern matching enhancements:模式匹配增强功能
- Performance and interop:性能和互操作性
- Native sized integers:本机大小的整数
- Function pointers:函数指针
- Suppress emitting localsinit flag:禁止发出 localsinit 标志
- Fit and finish features:调整和完成功能
- Target-typed new expressions:目标类型的 new 表达式
- static anonymous functions:static 匿名函数
- Target-typed conditional expressions:目标类型的条件表达式
- Covariant return types:协变返回类型
- Extension GetEnumerator support for foreach loops:扩展 GetEnumerator 支持 foreach 循环
- Lambda discard parameters:Lambda 弃元参数
- Attributes on local functions:本地函数的属性
- Support for code generators:支持代码生成器
- Module initializers:模块初始值设定项
- New features for partial methods:分部方法的新功能
C#8.0新特性
- Readonly members:Readonly 成员
- Default interface methods:默认接口方法
- Pattern matching enhancements:模式匹配增强功能
- Switch expressions:Switch 表达式
- Property patterns:属性模式
- Tuple patterns:元组模式
- Positional patterns:位置模式
- Using declarations:Using 声明
- Static local functions:静态本地函数
- Disposable ref structs:可处置的 ref 结构
- Nullable reference types:可为空引用类型
- Asynchronous streams:异步流
- Asynchronous disposable:异步可释放
- Indices and ranges:索引和范围
- Null-coalescing assignment:Null 合并赋值
- Unmanaged constructed types:非托管构造类型
- Stackalloc in nested expressions:嵌套表达式中的 Stackalloc
- Enhancement of interpolated verbatim strings:内插逐字字符串的增强功能
- Obsolete on property accessors:属性访问器已经过时
C#7.3新特性
- System.Enum, System.Delegate and unmanaged constraints:泛型约束,枚举、委托和非托管
- Ref local re-assignment:现在可以使用ref分配运算符(= ref)重新分配 Ref locals和ref参数。
- Stackalloc initializers:现在可以初始化堆栈分配的数组
- Indexing movable fixed buffers:索引可移动固定缓冲区
- Custom fixed statement:自定义fixed语句
- Improved overload candidates:改进重载候选项
- Expression variables in initializers and queries:初始化和查询中的表达式变量
- Tuple comparison:元组比较
- Attributes on backing fields:后备字段属性
C#7.2新特性
- Span and ref-like types ref-like类型的编译安全规则
- In parameters and readonly references:值类型的引用语法
- Ref conditional:条件ref
- Non-trailing named arguments:不在尾部的指定名字参数
- Private protected accessibility:访问修饰符
- Digit separator after base specifier:前缀数字(非十进制)分割
C#7.1新特性
- Async main:异步Main方法
- Default expressions:默认表达式
- Reference assemblies:参考程序集
- Inferred tuple element names:推断元组元素名称
- Pattern-matching with generics:泛型的模式匹配
C#7.0新特性
- Out variables:out变量直接声明,例如可以out in parameter
- Pattern matching:模式匹配,根据对象类型或者其它属性实现方法派发
- Tuple 元组
- Deconstruction:元组解析
- Discards:舍弃
- Local Functions:本地函数
- Binary Literals:二进制文字
- Digit Separators:数字分隔符
- Ref returns and locals:Ref返回和临时变量
- Generalized async return types:异步返回类型的广泛支持
- More expression-bodied members:更多表达式化的成员体
- Throw expressions:抛出表达式
C#6.0新特性
- Draft Specification online
- Compiler-as-a-service (Roslyn)
- Import of static type members into namespace:支持仅导入类中的静态成员
- Exception filters:异常过滤器
- Await in catch/finally blocks:支持在catch/finally语句块使用await语句
- Auto property initializers:自动属性初始化
- Default values for getter-only properties:设置只读属性的默认值
- Expression-bodied members:支持以表达式为主体的成员方法和只读属性
- Null propagator (null-conditional operator, succinct null checking):Null条件操作符
- String interpolation:字符串插值,产生特定格式字符串的新方法
- nameof operator:nameof操作符,返回方法、属性、变量的名称
- Dictionary initializer:字典初始化
C#5.0新特性
- Asynchronous methods 异步方法
- Caller info attributes:调用时访问调用者的信息
- foreach loop was changed to generates a new loop variable rather than closing over the same variable every time
C#4新特性
- Dynamic binding:动态绑定
- Named and optional arguments:命名参数和可选参数
- Generic co- and contravariance:泛型的协变和逆变
- Embedded interop types (“NoPIA”):开启嵌入类型信息,增加引用COM组件程序的中立性
C#3新特性
- Implicitly typed local variables
- Object and collection initializers
- Auto-Implemented properties
- Anonymous types
- Extension methods
- Query expressions, a.k.a LINQ (Language Integrated Query)
- Lambda expression
- Expression trees
- Partial methods
- Lock statement
C#2新特性
- Generics
- Partial types
- Anonymous methods
- Iterators, a.k.a yield statement
- Nullable types
- Getter/setter separate accessibility
- Method group conversions (delegates)
- Static classes
- Delegate inference
- Type and namespace aliases
- Covariance and contravariance
C#1.2新特性
- Dispose in foreach
- foreach over string specialization
C#1特性
- Classes
- Structs
- Enums
- Interfaces
- Events
- Operator overloading
- User-defined conversion operators
- Properties
- Indexers
- Output parameters (out and ref)
- params arrays
- Delegates
- Expressions
- using statement
- goto statement
- Preprocessor directives
- Unsafe code and pointers
- Attributes
- Literals
- Verbatim identifier
- Unsigned integer types
脚本限制
参考资料:
C#更新列表
C#documentation
C#参考
Unity2020.2中支持的C#8有什么新特性
[Unity脚本运行时更新]C#7.2新特性
[Unity脚本运行时更新]C#7.1新特性
[Unity脚本运行时更新]C#7新特性
[Unity脚本运行时更新]C#6新特性
[Unity脚本运行时更新]C#5新特性
[Unity脚本运行时更新]C#4新特性