zoukankan      html  css  js  c++  java
  • C#中 @ 的用法

    using System.Data.SqlClient;
    using System.Data;
    using System;
    class MyClass
    {

        
    void Test()
        
    {
            
    // 1 加在字符串前面,字符串中的 \ 失去转义符的作用,直接写字符串而不需要考虑转义字符
            string path = @"C:\Windows\"// 如果不加 @,编译会提示无法识别的转义序列

            
    // 如果不加 @,可以写成如下
            string path2 = "C:\\Windows\\";

            
    // 2 加在字符串前面,字符串中的 " 要用 "" 表示
            string str = @"aaa=""bbb""";
            
    // 不加 @,可以写成
            string str2 = "aaa=\"bbb\"";

            
    // 3 加在字符串前面,换行空格都保存着,方便阅读代码
            string insert = @"
                insert into Users
                (
                    UserID,
                    Username,
                    Email
                ) values
                (
                    @UserID,
                    @Username,
                    @Email
                )
    ";


            
    // 4 用关键字做变量时在关键字前面加@ 
            string @operator = "+";
            
    string @class = "分类一";

            Console.WriteLine(@operator);
            Console.WriteLine(@class);


            
    // 5 作为sql语句里的一个“标签”,声明此处需要插入一个参数 
            string delete = "delete from Categery where CategoryID=@CategoryID";
            SqlConnection connection 
    = new SqlConnection("connectionString");
            SqlCommand command 
    = new SqlCommand(delete, connection);
            command.Parameters.Add(
    "@CategoryID", SqlDbType.BigInt);

        }
     // Test()

    }
    // class MyClass
  • 相关阅读:
    Jenkins pipeline基本结构
    接口测试框架httprunner使用自定义extentreports报告模板遇到的问题小结
    python3中扩展字典类实现用点访问属性
    python3系列五可迭代对象、迭代器和生成器
    vue.js-组件嵌套
    使用Vue-CLI3.x进行vue.js环境搭建
    python系列四反射机制
    vue.js环境搭建踩坑记
    python系列三推导式
    python系列二filter()、map()和reduce()
  • 原文地址:https://www.cnblogs.com/yangbin1005/p/1171581.html
Copyright © 2011-2022 走看看