简体   繁体   English

MS C# 教程代码在 VS2013 中不起作用?

[英]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.

相关问题 C#Intellisense VS2013工具提示未显示XML注释(我尝试全部) - c# Intellisense VS2013 tooltip doesn't show XML comments (i try all) 在VS2013中查找C#代码中的异常隐藏/吞咽 - Find exception hiding/swallowing in C# code in VS2013 在VS2013中为C#创建自定义代码段 - Creating Custom Code Snippet in VS2013 for C# VS2013上C#的VTK包装 - VTK wrap for C# on VS2013 从VS2012升级到VS2013后,SGEN无法工作 - SGEN doesn't work after upgrading from VS2012 to VS2013 JS .hover可见性不起作用(ASP.NET,VS2013,Web表单) - JS .hover visibility doesn't work (ASP.NET, VS2013, web forms) 在VS2013中编译ASP.NET MVC项目在发行版中不起作用 - Compile ASP.NET MVC Project in VS2013 doesn't work in release 文件无法删除,并且复制和移动在C#VS2013中不起作用 - a file cannot be deleted and copy and move do not work in C# VS2013 SQLite 的 dotConnect 包不适用于 VS2013 中的 64 位 C# 项目? - the package of dotConnect for SQLite does not work for 64 bits C# project in VS2013? 为什么“记住我”在 VS2013 的 ASP.NET MVC 5 样板代码中不起作用? - Why won't 'Remember Me' work in VS2013's ASP.NET MVC 5 boilerplate code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM