c#代码格式化的长行

KgO*_*ogs 1 c# code-formatting

我写了这行代码.这是不可读的.是否有巧妙的方法将其分解为多行代码<80或100个字符长度?

Console.WriteLine(String.Join("\n", testResults.Select(row => String.Join("|", row.Select(column => String.Format("{0,20}", column.ToString()))))));

Dmi*_*nko 6

我建议分离查询本身及其最终表示(控制台输出):

// Query: what to output
var testReport = testResults
  .Select(row => String.Join("|", row
     .Select(column => String.Format("{0,20}", column)))); // .ToString() is redundant

// Representation: how to output (print on the console in one go)
Console.WriteLine(String.Join(Environment.NewLine, testReport));
Run Code Online (Sandbox Code Playgroud)