【问题标题】:How to write statement in Console.WriteLine so that it prints in separate lines如何在 Console.WriteLine 中编写语句,以便它在单独的行中打印
【发布时间】:2023-01-03 21:05:27
【问题描述】:

我想在 Console.WriteLine 中写一行,这样每个部分都应该打印在单独的行上,暂时我用 \r\n 格式化了但是很难管理,有什么好的选择吗?

Console.WriteLine("\n你需要执行什么操作\r\nA-加法:\r\nS-减法:\r\nM-乘法:\r\nL-FindLargestElementInMatrix:\r\nS-FindSmallestElementInMatrix:\r\ nDL-DisplayLowerTriangularMatrix:\r\nDU-DisplayUpperTriangularMatrix:\r\nT-FindTransposeOfMatrix:\r\nE-CheckIfTwoMatricesEqual:\r\nI-CheckIfTwoMatrixIsIdentityMatrix:\r\nS-SumOfDiagonalElementsOfMatrix:\r\nAR-SumOfEach:owRowRowMatrix -SumOfEachColumnOfMatrix:\r\nIR-InterchangeRowsOfMatrix:\r\nIC-InterchangeColumnsOfMatrix:“);

我想在 Console.WriteLine 中写一行,这样每个部分都应该打印在单独的行上,暂时我用 \r\n 格式化了但是很难管理,有什么办法吗?

【问题讨论】:

    标签: c#


    【解决方案1】:

    在 C# 11 中,您可以使用 raw string literal

    string output = """
        What Operation you need to perform
        A-Addition:
        S-Subtraction:
        ...
        """
    Console.WriteLine(output);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多