惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - 简约旋律

如何做一名优秀的部门经理 viewstate 的工作原理 Repeater/DataList分页方法 char与varchar的区别 堂堂正正做人 认认真真做事 笨鸟 节约时间 ASP.NET中的FILE对象总结 当梦想照进现实 数据库事务 读写删文件代码 什么是SQL注入及SQL注入工具 void的使用 导航树扩展 按F5运行时出现目录清单 经典JS收藏 GET POST的使用 关于request的一个问题 一些代码
(C#) C#中的@符号
简约旋律 · 2007-11-08 · via 博客园 - 简约旋律


C#中的@符号

2005-7-27

Allen

@符号是特殊而又实用的C#符号。

比如它在string中的应用。

1

字符@表示,其后的字符串是个“逐字字符串”(verbatim string)。 // 这个说法来自C# Primer 中文版(Stanley B. Lippman, 侯捷/陈硕合译)

2

对于逐字字符串字面变量(verbatim string literal ),我们不再需要使用“转义序列”就可以指定反斜线之类的特殊字符。@的这个特点使得在表示文件路径时很方便。

如:

string str = @"C:\Test.txt";

3

另外一点,用@表示的字符串能够跨越数行。这数行之内的空白字符(White Space)都会保留在字符串里。

这样便能允许存储和生成带有格式的文本块。

如:

string strText = @"Line1

Line2

Line3";

有意思的是如果在VS.NET2003中当你输入完第一行(string strText = @"Line1)换行后,光标会自动到第二行最开头 ^_^。很智能化、人性化的判断。

4

不知道大家在最初看到@的功能时有没有想,如果“转义序列”(\)在字符串中“失效”,那么想包含一个双引号("),怎么办?我找到了答案。

方法很简单。在双引号之前再加一个双引号即可。

如:

string str = @"""Great!""Said Allen Lee";

5

这仅仅是@在字符串中的用法,有机会再去看看@的其他东东。