类成员寻址 [英] Class member addressing

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

问题描述




我被教导使用这种类/成员构造(有些年份

前我可能会添加) -


class someclass

{

private datatype data1;

private datatype data2;


public someclass(datatype data1,datatype data2 etc)

{

this.data1 = data1;

this.data2 = data2;

等...


但很多现代文本似乎都在谴责使用''this'来

前缀/访问类memebers,甚至似乎没有明确的

''私人''。这几天的规范是什么?谢谢!

Hi,

I was taught to use this type of class/member construction (some years
ago I might add) -

class someclass
{
private datatype data1;
private datatype data2;

public someclass( datatype data1, datatype data2 etc)
{
this.data1 = data1;
this.data2 = data2;
etc...

but alot of modern texts seem to decry the use of ''this'' to
prefix/access class memebers and don''t even seem to bother with explicit
''private''. What''s the ''norm'' these days? Thanks!

推荐答案

" MM" < mm@newsgroups.com>在消息中写道

新闻:OF ************** @ TK2MSFTNGP12.phx.gbl ...
"MM" <mm@newsgroups.com> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...

我被教导使用这种类/成员构造(几年前我可能会添加) -

类someclass
{
私人数据类型data1;
私有数据类型data2;

公共someclass(数据类型data1,数据类型data2等)
这个数据类型为数据类型;数据类型data2 = data2;
等...

但很多现代文本似乎都在谴责使用''this'来添加/访问
类memebers而不是'''甚至似乎对明确的私人感到困扰。
这些日子的规范是什么?谢谢!
Hi,

I was taught to use this type of class/member construction (some years ago
I might add) -

class someclass
{
private datatype data1;
private datatype data2;

public someclass( datatype data1, datatype data2 etc)
{
this.data1 = data1;
this.data2 = data2;
etc...

but alot of modern texts seem to decry the use of ''this'' to prefix/access
class memebers and don''t even seem to bother with explicit ''private''.
What''s the ''norm'' these days? Thanks!




我发现这个更清楚:


私有数据类型_data1;

私有数据类型_data2 ;


Michael



I find this clearer:

private datatype _data1;
private datatype _data2;

Michael


嗨MM,

我更喜欢像Michael C一样放一个私人会员旁边的下划线

变量以提高可读性。我个人也喜欢添加这个 inforont

变量,但这只是个人偏好我觉得它使代码更清楚b / b
清楚,其他人可能不同意。我认为在编码时最好明确表示变量,例如声明变量私有,因为这也有助于提高可读性。


微软有一些编写的编码指南班级图书馆,这是值得阅读的
。查看
http://msdn.microsoft.com/library/de...guidelines.asp

希望有所帮助

Mark R Dawson


" MM"写道:
Hi MM,
I prefer, like Michael C, to put an underscore next to private member
variables to aid readability. I also personally like adding "this" inforont
of variables but it is just personal preference I think it makes code more
clear, others may disagree. I think that when coding it is better to be
explicit, such as declaring variables private as this also aids readability.

Microsoft has some coding guidlelines for writing class libararies, which is
worth reading. Check out
http://msdn.microsoft.com/library/de...guidelines.asp

Hope that helps
Mark R Dawson

"MM" wrote:


我被教导使用这种类/成员构造(有些年前我可能会添加) - <类someclass
私有数据类型data1;私有数据类型data2;
公共someclass(数据类型data1,数据类型data2等)
{
this.data1 = data1;
this.data2 = data2;
等......
但很多现代文本似乎都在谴责使用''this''
前缀/访问类memebers,甚至似乎都没有明确的
''private''。这几天的规范是什么?谢谢!
Hi,

I was taught to use this type of class/member construction (some years
ago I might add) -

class someclass
{
private datatype data1;
private datatype data2;

public someclass( datatype data1, datatype data2 etc)
{
this.data1 = data1;
this.data2 = data2;
etc...

but alot of modern texts seem to decry the use of ''this'' to
prefix/access class memebers and don''t even seem to bother with explicit
''private''. What''s the ''norm'' these days? Thanks!



MM< mm@newsgroups.com>写道:
MM <mm@newsgroups.com> wrote:


我被教导使用这种类/成员构建(有些年前我可能会添加) -

class someclass
私有数据类型data1;
私有数据类型data2;
公共someclass(数据类型data1,数据类型data2等)
{
this.data1 = data1;
this.data2 = data2;
等...

但很多现代文本似乎都在谴责''this'的使用'
前缀/访问班级成员


这是个人选择。在工作中我使用m_variableName由于那里的编码标准是

,但在家里我写的代码如上。所以

只要变量保持私密,它没有任何可能性。

,甚至似乎都没有明确的
''私人''。这几天的规范是什么?谢谢!
Hi,

I was taught to use this type of class/member construction (some years
ago I might add) -

class someclass
{
private datatype data1;
private datatype data2;

public someclass( datatype data1, datatype data2 etc)
{
this.data1 = data1;
this.data2 = data2;
etc...

but alot of modern texts seem to decry the use of ''this'' to
prefix/access class memebers
It''s a personal choice. At work I use "m_variableName" due to the
coding standards there, but at home I write code like the above. So
long as the variables stay private, it makes no odds.
and don''t even seem to bother with explicit
''private''. What''s the ''norm'' these days? Thanks!




是否明确说明私人或者不是更多的个人选择 - 它与生成的

代码没有任何*差异。就我个人而言,我不打扰它 - 因为C#

的默认值是如此精心挑选(总是限制性最强的访问)我

更喜欢将它突出显示为我已经做了*少了*

限制性的。


-

Jon Skeet - < sk * **@pobox.com>
http://www.pobox.com/ 〜双向飞碟

如果回复小组,请不要给我发邮件



Whether you explicitly state "private" or not is even more of a
personal choice - it doesn''t make *any* difference to the generated
code. Personally I don''t bother with it - because the defaults in C#
are so well chosen (always the most restrictive access available) I
prefer to have it highlighted to me that I''ve made something *less*
restrictive.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


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

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