在Visual Studio 2008中打破长代码行

muh*_*han 20 c#

在Visual Studio 2008中,如果我有一长串代码,我怎样才能将其分解为多行?

public static void somemethod(param1, param2, param3, more params etc...)
Run Code Online (Sandbox Code Playgroud)

如何使这1行代码跨越2或3行?

Tim*_*ker 31

点击回车键.

public static somemethod(param1, 
    param2, 
    param3, 
    more params etc...)
Run Code Online (Sandbox Code Playgroud)

......完全有效.


Guf*_*ffa 13

C#不是基于行的,因此您可以将语句拆分到标识符内的任何位置:

public static void somemethod(
   int param1,
   int param2,
   int param3,
   more params etc...
)
Run Code Online (Sandbox Code Playgroud)

你甚至可以写下这样的东西:

for
(
int
i
=
0
;
i
<
10
;
i
++
) 
{
Console
.
WriteLine
(
i
)
;
}
Run Code Online (Sandbox Code Playgroud)


小智 8

要打破字符串,你可以_在VB.Net和C#中放置一个中断@字符串.

C#中的代码:

string s=@"sdsdsdsd
dfdfdfdfdf
fdfdfdfdf";
Run Code Online (Sandbox Code Playgroud)

VB中的代码

s="fdfdfdfdfdf _
dfdfdfdfdfdf "
Run Code Online (Sandbox Code Playgroud)


Sam*_*ell 5

您有几个选择:

  1. 工具 > 选项 > 所有语言 > 常规 > 启用自动换行
  2. 在“在文件中查找”对话框中使用以下正则表达式在项目中查找长行(本例中为 120 个字符),以便可以拆分它们?
    ^.^120

编辑:看到标记的答案 - 我宁愿假设该部分是已知的。:o