zoukankan      html  css  js  c++  java
  • C#中的字符串拼接@,$

    转载自:https://blog.csdn.net/qq_40666620/article/details/101695138

    一:@
    @的意思是以@标注的字符出,其中所有的符号均为字符串符号,没有什么特殊字符,如’'什么的,均默认为字符串

    static void Main(string[] args)
            {
            //这样就很方便写读取的文件路径,也不需要什么转义字符了
                 StreamReader sr = new StreamReader(@"C:UsersWANGWI8Desktop	estStreamRead.txt");
                 string line;
                 while( (line = sr.ReadLine()) != null )
                 {
                     Console.WriteLine(line);
                 }
             }

    二:$
    $的意思是以它标注的字符串中,可用中括号取值:

      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}";
                Console.WriteLine(result);
    
                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(" ");
                //负号的意思是左对齐,一共占据25个字符的空间
                Console.WriteLine($"|{"item",-25}|{"quantity",10}|");
                foreach (var item in inventory)
                    Console.WriteLine($"|{item.Key,-25}|{item.Value,10}|");
    
            }
  • 相关阅读:
    POJ 1659 Frogs' Neighborhood
    zoj 2913 Bus Pass(BFS)
    ZOJ 1008 Gnome Tetravex(DFS)
    POJ 1562 Oil Deposits (DFS)
    zoj 2165 Red and Black (DFs)poj 1979
    hdu 3954 Level up
    sgu 249 Matrix
    hdu 4417 Super Mario
    SPOJ (BNUOJ) LCM Sum
    hdu 2665 Kth number 划分树
  • 原文地址:https://www.cnblogs.com/wsxdev/p/15464607.html
Copyright © 2011-2022 走看看