加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

您如何在Delphi和C#中格式化您的复合语句?

发布时间:2020-12-15 04:30:10 所属栏目:大数据 来源:网络整理
导读:长期以来,Pascal和Delphi开发人员,我总是排队我的开始和结束: begin if x = y then begin ... ... end else for i := 0 to 20 do begin ... ... end;end; 什么驱动我坚果是代码格式化: begin if x = y then begin ... ... end else for i := 0 to 20 do be
长期以来,Pascal和Delphi开发人员,我总是排队我的开始和结束:
begin
  if x = y then
  begin
     ...
     ...
  end
  else
    for i := 0 to 20 do
    begin
      ...
      ...
    end;
end;

什么驱动我坚果是代码格式化:

begin
  if x = y then begin
     ...
     ...
  end
  else
    for i := 0 to 20 do begin
      ...
      ...
    end;
end;

当有几个级别的复合语句我发现这很难阅读.上面的代码是可以的,因为它不是那么复杂,但是为了一致性,我更喜欢所有的开始和结束对齐.

当我开始使用c#时,我发现自己也卷曲括号. C#世界的规范是什么?

编辑:

有人指出,这是不应该在这个问题上提出的问题.我不明白为什么不这样.我正在设置编码指南文件.我知道我会对某些事情有所抵制,我希望在这里得到一些答案,所以我可以准备好迎接这个阻力了.

解决方法

我个人使用:
if Condition then
begin
  DoThis;
end else
begin
  DoThat;
end;

见Object Pascal Style Guide.

In compound if statements,put each
element separating statements on a new
line: Example:

// INCORRECT
if A < B then begin
  DoSomething; 
  DoSomethingElse;
end else begin
  DoThis;
  DoThat;
end;

// CORRECT
if A < B then 
begin
  DoSomething; 
  DoSomethingElse;
end 
else 
begin
  DoThis;
  DoThat;
end;

Here are a few more variations that are considered valid:

// CORRECT
if Condition then
begin
  DoThis;
end else
begin
  DoThat;
end;

// CORRECT
if Condition then
begin
  DoThis;
end
else
  DoSomething;

// CORRECT
if Condition then
begin
  DoThis;
end else
  DoSomething;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读