Explain string splicing in C # @$



@It means the character marked with @ in which all symbols are string symbols. There are no special characters, such as’ ‘, which are string by default

static void Main(string[] args)
    //In this way, it is convenient to write and read the file path, and there is no need for any escape characters
     StreamReader sr = new StreamReader(@"C:\Users\WANGWI8\Desktop\testStreamRead.txt");
     string line;
     while( (line = sr.ReadLine()) != null )


$means that the string marked with it can be taken in brackets:

static void Main(string[] args)
      var name = Console.ReadLine();
      var date = DateTime.Now;
      var result = $"hello {name} , you are my father , i am your son , writed at {date}";
      var item2 =
        name: "william",
        sex: 'f'
      Console.WriteLine($"this is item : item.name : {item2.name} , this is sex : {item2.sex}");
      var inventory = new Dictionary<string, int>()
        ["hammer, ball pein"] = 18,
        ["hammer, cross pein"] = 5,
        ["screwdriver, Phillips #2"] = 14
      Console.WriteLine($"inventory on {DateTime.Now:d}");
      Console.WriteLine(" ");
      //The minus sign means left aligned, occupying a total of 25 characters
      foreach (var item in inventory)


The above is the string splicing @ $, in c# introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support to the developeppaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]