我目前正在 C# 中使用 Visual Studio for Mac 编写要在 Unity 中使用的脚本,它告诉我不能使用“插值字符串”(因为它在 C# 4 中不可用,仅在版本 6 或更高版本中可用)。我一直在寻找更改语言版本的选项,但没有找到。请告诉我是否配置错误或有任何方法可以更改语言版本。提前致谢。
最佳答案
您可以从 ( Updated scripting runtime in Unity ) 更改脚本运行时语言
Edit->Project Settings->Player->Other Settings->Configuration->Scripting Runtime Version.
<强> String interpolation 是从 c#6
版本引入的,对于较低版本,您可以使用 string.Format()
相反,基本上是一样的,只是写得长一点。字符串插值是 syntactic sugar对于string.Format()
。
例如:
int num = 10;
string str = $"Number: {num}";
是一样的:
int num = 10;
string str = string.Format("Number: {0}", num);
关于c# - Visual Studio for mac C#语言版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50694333/