会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
滨_Notepad
学习工作点滴积累
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
公告
C#中 @ 的用法
Posted on
2008-04-25 21:47
新人~
阅读(
312
) 评论(
0
)
编辑
收藏
举报
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
会员力量,点亮园子希望
刷新页面
返回顶部
Powered by:
博客园
Copyright © 2024 新人~
Powered by .NET 8.0 on Kubernetes