environment.NewLine

来源:互联网 发布:淘宝宝贝分类怎么删除 编辑:程序博客网 时间:2024/04/28 02:21
将转义字符(\)当作普通字符对待,比如:string str = @"C:\Windows";如果我们去掉 @ 的话,应该是:string str = "C:\\Windows";@ 字符串中,我们用两个连续英文双引号表示一个英文双引号,如下字符串的实际内容为:="=,字符串长度为 3。string str = @"=""=";@ 字符串中可以任意换行,换行符及缩进空格都计算在字符串长度之内。string str = @"<script type=""text/javascript"">            <!--            -->            </script>";            Console.WriteLine(str);由于 @ 的这种特性,我们常将其应用到 SQL 字符串中。string sql = @"select * from tbl";@ 只在连续一段字符串中有效,@"abc" + "\\",用 + 将两个字符串连接起来,第二个字符串中没有用 @ 标识,其中的 \ 就成为转义字符。Second:在 C# 中,我们用字符串 "\r\n" 表示回车换行符。string str = "第一行\r\n第二行";但是我们更推荐 Environment.NewLine(名称空间为 System),Environment 是类,NewLine 是字符串属性,用于获取当前环境中定义的回车换行符字符串。string str = "第一行" + Environment.NewLine + "第二行";在 Windows 环境中,C# 语言 Environment.NewLine == "\r\n" 结果为 true。