大写 [英] Capitalisation

查看:85
本文介绍了大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚看过这个:

http://msdn.microsoft.com/library/de...tionstyles.asp


但是想知道VB.NET之类的语言是否会出现任何问题:


private int color;


public int Color

{

获得{返回颜色;}

}


只有小写版本才有所不同是私有的,

大写是公共的,是一个VB.NET编码器使用这个类他们能够

使用该属性好吗?

我只提这个,因为我总是这样设计我的属性和

我不想让我的代码无法被VB.NET开发人员使用。

I just read this:

http://msdn.microsoft.com/library/de...tionstyles.asp

But wondered if languages such as VB.NET would have any problems with:

private int color;

public int Color
{
get{return color;}
}

That only differs by case although the lower case version is private and the
uppercase is public, were a VB.NET coder to use the class would they be able
to use the property ok?
I only mention this because i''ve always designed my properties this way and
I wouldn''t like to make my code unusable by a VB.NET developer.

推荐答案

私有属性就是:private。一个VB.NET调用者只会看到

只有Color属性而不是私有颜色成员,并且在Color get方法的代码中有一次

,它就是全部IL无论如何。调用者可以发现有一个名为

" color"的私人成员的唯一

方式将通过Reflection,然后只有它是一个完全可信的

来电者。


这就是说,这不是一个好的编码实践。 FxCop,微软的免费赠品

编码风格检查器,会为此跳出来。我知道,因为我/ b $ b经常做同样的事情,而FxCop抱怨道。是的,这是一种痛苦的想法

私人会员与公共场所的新名称,但它是更好的编码练习。


就我而言,我使用私有成员的缩写,所以我可能有

公共属性Color返回私有

字段clr的内容,或者某事像那样。

Private properties are just that: private. a VB.NET caller will see
only the Color property and not the private color member, and once
inside the code of the Color get method, it''s all IL anyway. The only
way that a caller could find out that there is a private member called
"color" would be via Reflection, and then only if it is a fully trusted
caller.

That said, this is not good coding practice. FxCop, Microsoft''s freebie
coding style checker, will jump on you for this. I know, because I
often do the same thing, and FxCop complains. Yes, it''s a pain thinking
up new names for private members versus public properties, but it is
better coding practice.

For my part, I use abbreviations for private members, so I might have
the public property Color that returns the contents of the private
field clr, or something like that.


为了解决这个问题,我写的文章是针对

VB和C#用户我用的属性名为_color的属性支持字段

名为Color,一个名为_fred的名为Fred的属性。


这是我最好的方法已找到可能需要转换为

并在VB中分发的代码。


-

Bob Powell [ MVP]

Visual C#,System.Drawing


在Windows窗体中查找精彩的Windows窗体提示和技巧
http://www.bobpowell.net/tipstricks.htm

用GDI + FAQ回答那些GDI +问题
http://www.bobpowell.net/faqmain.htm


所有新文章都提供C#和VB.NET中的代码。

订阅所提供的RSS提要,绝不会错过任何新文章。

" Uchiha Jax" <我_ ************************ @ NOSPAMhotmail.com>在消息中写道

新闻:na *************** @ newsfe1-gui.ntli.net ...
To overcome this problem in the articles which I write that are targeted at
VB and C# users I use a property backing field named _color for a property
named Color and one called _fred for a property called Fred.

It''s the best method I''ve found for code that might need to be converted to
and distributed in VB.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Uchiha Jax" <i_************************@NOSPAMhotmail.com> wrote in message
news:na***************@newsfe1-gui.ntli.net...
我只是阅读本文:

http://msdn.microsoft.com/library/de...tionstyles.asp

但是想知道是否有像VB.NET这样的语言会有任何问题:

private int color;

public int Color
{
get {return color;}
} <虽然小写版本是私有的并且
大写是公共的,但只有大小写是公开的,这是一个VB.NET编码器来使用它们将是
能够使用这个属性好吗?
我只提这个因为我总是这样设计我的属性

我不想让我的代码无法使用由VB.NET开发人员提供。
I just read this:

http://msdn.microsoft.com/library/de...tionstyles.asp

But wondered if languages such as VB.NET would have any problems with:

private int color;

public int Color
{
get{return color;}
}

That only differs by case although the lower case version is private and
the
uppercase is public, were a VB.NET coder to use the class would they be
able
to use the property ok?
I only mention this because i''ve always designed my properties this way
and
I wouldn''t like to make my code unusable by a VB.NET developer.



你好!
那就是说,这不是很好的编码实践。微软的免费赠品编码风格检查器FxCop将为此向您倾斜。我知道,因为我经常做同样的事情,而FxCop抱怨道。是的,这是一种痛苦的想法,为私人会员和公共场所提供新名称,但这是更好的编码实践。
That said, this is not good coding practice. FxCop, Microsoft''s freebie
coding style checker, will jump on you for this. I know, because I
often do the same thing, and FxCop complains. Yes, it''s a pain thinking
up new names for private members versus public properties, but it is
better coding practice.




我不同意这里我认为是this.color。比

m_Color更具可读性,但我对使用前缀的参数感兴趣。


-

问候

Anders Borum / SphereWorks

微软认证专家(.NET MCP)



I don''t agree here. I think a "this.color" is much more readable than
m_Color, but I am interested in the arguments for using prefixes.

--
With regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)


这篇关于大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆