加深C# 中字符串前加@符号理解以及使用~~
来源:互联网 发布:微信相关软件 编辑:程序博客网 时间:2024/06/01 07:53
1、 用 @ 引起来的字符串以 @ 开头,并用双引号引起来。例如:
@"good morning" // a string literal
用 @ 引起来的优点在于换码序列“不”被处理,这样就可以轻松写出字符串,例如一个完全限定的文件名:
@"c:/Docs/Source/a.txt" // rather than "c://Docs//Source//a.txt"
若要在一个用 @ 引起来的字符串中包括一个双引号,请使用两对双引号:
@"""Ahoy!"" cried the captain." // "Ahoy!" cried the captain.
@ 符号的另一种用法是使用碰巧成为 C# 关键字的被引用的 (/reference) 标识符。有关更多信息,请参见 2.4.2 标识符。
2、
先看代码(以下代码使用在C#,环境ASP.NET):
protected void Page_Load(object sender, EventArgs e)
{
test1("/a");
test1(@"/a");
test2("/a");
test2(@"/a");
test3("/a");
test3(@"/a");
test4("/a");
test4(@"/a");
}
//参数不带@ 输出不带@
public void test1(string str)
{
Response.Write("test1:[" + str+"]
");
}
//参数不带@ 输出带@
public void test2(string str)
{
Response.Write("test1:[" + @str + "]
");
}
//参数带@ 输出不带@
public void test3(string @str)
{
Response.Write("test1:[" + str + "]
");
}
//参数带@ 输出带@
public void test4(string @str)
{
Response.Write("test1:[" + @str + "]
");
}
{
test1("/a");
test1(@"/a");
test2("/a");
test2(@"/a");
test3("/a");
test3(@"/a");
test4("/a");
test4(@"/a");
}
//参数不带@ 输出不带@
public void test1(string str)
{
Response.Write("test1:[" + str+"]
");
}
//参数不带@ 输出带@
public void test2(string str)
{
Response.Write("test1:[" + @str + "]
");
}
//参数带@ 输出不带@
public void test3(string @str)
{
Response.Write("test1:[" + str + "]
");
}
//参数带@ 输出带@
public void test4(string @str)
{
Response.Write("test1:[" + @str + "]
");
}
F5执行,猜猜什么结果!!嘿嘿~~
以下公布显示结果:
test1:[ ]
test1:[/a]
test1:[ ]
test1:[/a]
test1:[ ]
test1:[/a]
test1:[ ]
test1:[/a]
o(∩_∩)o...哈哈。
可以发现无论你后来给不给字串加@符号,都不管用了,只有在字符串产生的时候加@有效果!
- 加深C# 中字符串前加@符号理解以及使用~~
- 加深C# 中字符串前加@符号理解以及使用~~
- 字符串处理你(在字符串前加符号)
- 拼接字符串 在字符串前加5个符号 note:
- 7、在字符串前加5个符号"note:"
- C#中,变量前的@符号
- php中函数前加&符号的作用
- c#字符串 取最后一个符号前的字符
- C# 中@符号在字符串中的
- C# 中@符号在字符串中的作用
- C# 中@符号在字符串中的作用
- C#中字符串前面加@的作用
- python中字符串前加r或R简介
- python 中字符串前加r的用处
- python中字符串前加u,r,b的含义
- 总结下java中abstract_interface_final_static_加深理解
- SqlServer字符串前加N
- 字符串前加 _T含义
- MyISAM 和 InnoDB 的区别(经典面试题)
- 如何在32位ubuntu11.10 下编译android 4.0.1源码和goldfish内核
- C++实现建造者模式
- hdu 1059 Dividing(多重DP)
- 解决部分电脑不能安装Linux问题
- 加深C# 中字符串前加@符号理解以及使用~~
- ZOJ 1011 NTA(二叉树+vector)
- JSP转译成Servlet详细过程
- C#中String和string区别
- 定制的UIAlertView在显示时出现抖动的现象
- 不高兴的小明
- 哎,人生的选择题
- 值传递和引用传递
- SGU 549 - Dumbbells