none
string interpolation RRS feed

  • Question

  • I was trying to apply string interpolation in visual studio 2017 but getting errors about this expression.

    Any hint please

    Regards


    tan

    Wednesday, October 4, 2017 11:54 AM

Answers

  • Hi,

    Documentation is here : https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interpolated-strings

    This is available since C# 6.0 (VS2015) be sure your project use this version of C#.

    I you want more help, could you show your code and the errors, because without that it's not possible to help.

    Regards,


    Yan Grenier

    Merci de bien vouloir "Marquer comme réponse", les réponses qui ont répondues à votre question, et de noter les réponses que vous avez trouvé utiles.

    Wednesday, October 4, 2017 1:21 PM
  • Hi tanvir,

    It is working on my end using Visual Studio 2017. Please look into below code. Also you didn't specify on which expression you are getting error.

    static void Main(string[] args)
            {
                var name = "Horace";
                var age = 34;
                var s1 = $"He asked, \"Is your name {name}?\", but didn't wait for a reply.";
                Console.WriteLine(s1);
    
                var s2 = $"{name} is {age:D3} year{(age == 1 ? "" : "s")} old.";
                Console.WriteLine(s2);
                //Console.WriteLine("Hello World");
                Console.ReadLine();
            }


    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Wednesday, October 4, 2017 8:47 PM
    Moderator

All replies

  • String interpolation works in VS 2017.

    Make sure the project created is a C# project.

    It would help if you post what you tried.


    «_Superman_»
    Microsoft MVP (Visual C++)(October 2009 - September 2013)

    Polymorphism in C

    Wednesday, October 4, 2017 12:07 PM
  • Hi,

    Documentation is here : https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interpolated-strings

    This is available since C# 6.0 (VS2015) be sure your project use this version of C#.

    I you want more help, could you show your code and the errors, because without that it's not possible to help.

    Regards,


    Yan Grenier

    Merci de bien vouloir "Marquer comme réponse", les réponses qui ont répondues à votre question, et de noter les réponses que vous avez trouvé utiles.

    Wednesday, October 4, 2017 1:21 PM
  • Hi tanvir,

    It is working on my end using Visual Studio 2017. Please look into below code. Also you didn't specify on which expression you are getting error.

    static void Main(string[] args)
            {
                var name = "Horace";
                var age = 34;
                var s1 = $"He asked, \"Is your name {name}?\", but didn't wait for a reply.";
                Console.WriteLine(s1);
    
                var s2 = $"{name} is {age:D3} year{(age == 1 ? "" : "s")} old.";
                Console.WriteLine(s2);
                //Console.WriteLine("Hello World");
                Console.ReadLine();
            }


    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Wednesday, October 4, 2017 8:47 PM
    Moderator
  • Hello,

    Without seeing what you have tried it's impossible to provide a solution. If you have read the documentation provided and still have issues post a small code sample using the code button to properly show your code.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, October 5, 2017 12:12 AM
    Moderator