1

想知道两者是否有区别。解释将不胜感激..

4

2 回答 2

2

写线()

默认行终止符是一个字符串,其值是一个回车后跟一个换行符(在 C# 中为“\r\n”,在 Visual Basic 中为 vbCrLf)。

环境.新线

包含“\r\n”的字符串用于非 Unix 平台,或包含“\n”的字符串用于 Unix 平台。

于 2012-07-20T06:48:13.130 回答
1

结果相同,但代码不同。

    protected char[] CoreNewLine = new char[2]
    {
      '\r',
      '\n'
    };    
    public virtual void WriteLine(string value)
        {
          if (value == null)
          {
            this.WriteLine();
          }
          else
          {
            int length1 = value.Length;
            int length2 = this.CoreNewLine.Length;
            char[] chArray = new char[length1 + length2];
            value.CopyTo(0, chArray, 0, length1);
            if (length2 == 2)
            {
              chArray[length1] = this.CoreNewLine[0];
              chArray[length1 + 1] = this.CoreNewLine[1];
            }
            else if (length2 == 1)
              chArray[length1] = this.CoreNewLine[0];
            else
              Buffer.InternalBlockCopy((Array) this.CoreNewLine, 0, (Array) chArray, length1 * 2, length2 * 2);
            this.Write(chArray, 0, length1 + length2);
          }
        }
于 2012-07-20T06:48:13.453 回答