SorryEh
SorryEh

Reputation: 928

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. Throughout the tutorial it hasn't mentioned using anything side from System,

From 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}!");

If I remove the $ it outputs the sentence as it's written Hello {name}!

What could the issue be?

Upvotes: 0

Views: 52

Answers (2)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112712

Interpolated Strings (string literals starting with $") were introduced in 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 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).

Official Visual Studio Downloads site.

Upvotes: 7

Krika
Krika

Reputation: 463

This is how you do it the old way (pre c# 6.0).

Console.WriteLine(String.Format("Hello {0}", name));

Upvotes: 1

Related Questions