是否可以使用{}块来提高可读性和 代码的可维护性? 示例: //添加复选框列 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 youIts 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更多推荐
使用{}块来提高可读性
发布评论