使用{}块来提高可读性

编程入门 行业动态 更新时间:2024-10-27 04:34:56
本文介绍了使用{}块来提高可读性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以使用{}块来提高可读性和 代码的可维护性? 示例: //添加复选框列 DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn(); { column.HeaderText =" Include" ;; column.Name =" IsUsedInNotification"; column.FlatStyle = FlatStyle.Standard; column.ThreeState = false; column.ValueType = typeof(bool); column.TrueValue = true; column.FalseValue = false; } 谢谢

解决方案

9月23日,12:31 * pm," GS" < gstoy ... @ gmailwrote:

是否可以使用{}块来提高可读性和 可维护性代码? 示例: //添加复选框列 DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn(); { * * * * column.HeaderText =" Include" ;; * * * * column.Name =" IsUsedInNotification" ; * * * * column.FlatStyle = FlatStyle.Standard; * * * * column.ThreeState = false; * * * * column.ValueType = typeof(bool); * * * * column.TrueValue = true; * * * * column.FalseValue = false; } 谢谢

它完全有效的代码......不过我个人更喜欢使用#regions 相同。 -Cnu

GS < gs ****** @ gmailwrote:

是否可以使用{}块来提高可读性和 代码的可维护性? 示例: //添加复选框列 DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn (); { column.HeaderText =" Include"; column.Name =" IsUsedInNotification" ;; column.FlatStyle = FlatStyle.Standard; column.ThreeState = false; column.ValueType = typeof(bool); column.TrueValue = true; column.FalseValue = false; }

It'a有点奇怪,但一般都没关系。如果你正在使用C#3, ,你可以用对象初始化器做得更好: DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn { HeaderText =" Include"; Name =" IsUsedInNotification"; FlatStyle = FlatStyle.Standard; ThreeState = false; ValueType = typeof(bool); TrueValue = true; FalseValue = false; }; - Jon Skeet - < sk *** @ pobox> 网站: www.pobox/~skeet 博客: http://www.msmvps。 com / jon.skeet C#深度: http:// csharpindepth

啊。不久前我在使用XmlTextWriter时做了这个。我将修改我的 使用它的最新代码并将其放入:-) writer.WriteStartElement(" thing"); { writer.WriteAttributeString(" name"," eggs"); writer.WriteAttributeString(" size"," 7") ; writer.WriteStartElement(" innerThing"); { 等 } writer.WriteEndElement(); } writer.WriteEndElement(); 不确定放置{和}的位置,但它看起来比这更好 writer.WriteStartElement(" thing"); writer.WriteAttributeString(" name"," eggs"); writer.WriteAttributeString(" size"," 7"); writer.WriteStartElement(" innerThing"); 等 writer.WriteEndElement(); writer.WriteEndElement(); 如果WriteStartElement返回一个IDisposable wouldn'会很棒t将其。 皮特

Is it acceptable to use { } blocks to improve readability and maintainability of the code? Example: //add the checkbox column DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn(); { column.HeaderText = "Include"; column.Name = "IsUsedInNotification"; column.FlatStyle = FlatStyle.Standard; column.ThreeState = false; column.ValueType = typeof(bool); column.TrueValue = true; column.FalseValue = false; } thank you

解决方案

On Sep 23, 12:31*pm, "G.S." <gstoy...@gmailwrote:

Is it acceptable to use { } blocks to improve readability and maintainability of the code? Example: //add the checkbox column DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn(); { * * * * column.HeaderText = "Include"; * * * * column.Name = "IsUsedInNotification"; * * * * column.FlatStyle = FlatStyle.Standard; * * * * column.ThreeState = false; * * * * column.ValueType = typeof(bool); * * * * column.TrueValue = true; * * * * column.FalseValue = false; } thank you

Its perfectly valid code.. however I personally prefer using #regions for the same. -Cnu

G.S. <gs******@gmailwrote:

Is it acceptable to use { } blocks to improve readability and maintainability of the code? Example: //add the checkbox column DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn(); { column.HeaderText = "Include"; column.Name = "IsUsedInNotification"; column.FlatStyle = FlatStyle.Standard; column.ThreeState = false; column.ValueType = typeof(bool); column.TrueValue = true; column.FalseValue = false; }

It''s a little bit odd, but generally okay. If you''re using C# 3, however, you can do even better with an object initializer: DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn { HeaderText = "Include"; Name = "IsUsedInNotification"; FlatStyle = FlatStyle.Standard; ThreeState = false; ValueType = typeof(bool); TrueValue = true; FalseValue = false; }; -- Jon Skeet - <sk***@pobox> Web site: www.pobox/~skeet Blog: www.msmvps/jon.skeet C# in Depth: csharpindepth

Ah. I did this some time ago when using XmlTextWriter. I will revise my newest code that uses it and put some in :-) writer.WriteStartElement("thing"); { writer.WriteAttributeString("name", "eggs"); writer.WriteAttributeString("size", "7"); writer.WriteStartElement("innerThing"); { etc } writer.WriteEndElement(); } writer.WriteEndElement(); Not sure where to put the { and }, but it looks better than this writer.WriteStartElement("thing"); writer.WriteAttributeString("name", "eggs"); writer.WriteAttributeString("size", "7"); writer.WriteStartElement("innerThing"); etc writer.WriteEndElement(); writer.WriteEndElement(); Would be great if WriteStartElement returned an IDisposable wouldn''t it. Pete

更多推荐

使用{}块来提高可读性

本文发布于:2023-11-06 01:50:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562415.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可读性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!