zoukankan      html  css  js  c++  java
  • string 字符串前加“$”“@”“$@”分别的作用

    举个例子,依然拿我之前那篇用过的学生(简化)

    public class Student
    {
        private int id;
    
        public int ID
        {
            get { return id; }
            set { id = value; }
        }
    }
    

    其他前提

    Student student = new Student() { ID = 1 };
    
    List<string> arr = new List<string>();
    

    分别回车看效果

    string a = @"12345
    6789";
    arr.Add(a);
    string b = $"12345" +
                    $"6789";
    arr.Add(b);
    string c = $@"12345
    6789";
    arr.Add(c);
    

    结果:

    所以@和$@都可以写多行连续的字符串,一般写很长的连表查询sql语句的时候用的多
    a = @"{nameof(Student.ID)} = {student.ID}";
    arr[0] = a;
    b = $"{nameof(Student.ID)} = {student.ID}";
    arr[1] = b;
    c = $@"{nameof(Student.ID)} = {student.ID}";
    arr[2] = c;
    

    结果:

    所以$和$@都可以将值直接放在字符串内,就不用每次写成这样nameof(Student.ID) + " = " + student.ID,写着也麻烦
  • 相关阅读:
    python shellcod加载器修改特征值
    python shellcode 分析二
    python shellcode分析
    Hadoop综合大作业1
    Hadoop综合大作业
    分布式文件系统HDFS
    安装Hadoop
    爬虫综合大作业
    爬取全部的校园新闻
    理解爬虫原理
  • 原文地址:https://www.cnblogs.com/AlinaL/p/13322492.html
Copyright © 2011-2022 走看看