先看代码(以下代码使用在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 + " ]<br/> " );
}
// 参数不带@ 输出带@
public void test2( string str)
{
Response.Write( " test1:[ " + @str + " ]<br/> " );
}
// 参数带@ 输出不带@
public void test3( string @str)
{
Response.Write( " test1:[ " + str + " ]<br/> " );
}
// 参数带@ 输出带@
public void test4( string @str)
{
Response.Write( " test1:[ " + @str + " ]<br/> " );
}
{
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 + " ]<br/> " );
}
// 参数不带@ 输出带@
public void test2( string str)
{
Response.Write( " test1:[ " + @str + " ]<br/> " );
}
// 参数带@ 输出不带@
public void test3( string @str)
{
Response.Write( " test1:[ " + str + " ]<br/> " );
}
// 参数带@ 输出带@
public void test4( string @str)
{
Response.Write( " test1:[ " + @str + " ]<br/> " );
}
F5执行,猜猜什么结果!!嘿嘿~~
以下公布显示结果:
o(∩_∩)o...哈哈。
可以发现无论你后来给不给字串加@符号,都不管用了,只有在字符串产生的时候加@有效果!
本文转自博客园农民伯伯的博客,原文链接:加深C# 中字符串前加@符号理解以及使用~~,如需转载请自行联系原博主。