[英]MS C# tutorial code doesn't work in VS2013?
I'm following through Microsoft's C# tutorial to eventually learn .net, I've put this code into my VS 2013 and for some reason the output shows that "$" was an unexpected character.我正在学习 Microsoft 的C# 教程以最终学习 .net,我已将此代码放入我的 VS 2013 中,出于某种原因,输出显示“$”是一个意外字符。 Throughout the tutorial it hasn't mentioned using
anything side from System,在整个教程中,它没有提到using
System 的任何方面,
From MS来自 MS
using System;
class Program
{
static void Main()
{
var name = "Steve"; // use your name here
Console.WriteLine($"Hello {name}!");
}
}
What I have我拥有的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
var name = "John";
Console.WriteLine($"Hello {name}!");
}
}
}
VS2013 says it was expecting a ')' in the part of the line where its written ($"Hello {name}!");
VS2013 表示它期望在其写入的行的部分中出现一个 ')' ($"Hello {name}!");
If I remove the $ it outputs the sentence as it's written Hello {name}!如果我删除 $ 它会输出句子,因为它写的是Hello {name}!
What could the issue be?可能是什么问题?
Interpolated Strings (string literals starting with $"
) were introduced in C# 6.0 (Visual Studio 2015). C# 6.0 (Visual Studio 2015) 中引入了内插字符串(以$"
开头的字符串文字)。
Note that you can download and use the free Community Edition of Visual Studio 2015, if you are student, an open-source developer or and individual developer.请注意,如果您是学生、开源开发人员或个人开发人员,您可以下载并使用 Visual Studio 2015 的免费社区版。 Visual Studio 2017 is Launching on March 7 2017 and also has a free Community Edition and supports C#7.0 (introducing tuples with the new tuple syntax, pattern matching and much more). Visual Studio 2017 将于 2017 年 3 月 7 日推出,还有一个免费的社区版并支持C#7.0 (引入具有新元组语法、模式匹配等的元组)。
Official Visual Studio Downloads site.官方Visual Studio 下载站点。
这就是您如何以旧方式(c# 6.0 之前)执行此操作。
Console.WriteLine(String.Format("Hello {0}", name));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.