使用'基地'。 [英] use of 'base.'

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

问题描述

我有一些我正在更新的基类字段。我不需要使用

''base''修饰符来限定对我的字段的引用,但它的使用是否会增加

的可读性?大多数人在C#中做了什么?


base.isValid = true;



isValid = true;


两者都有效。哪个更好?


谢谢。


-


Andrew Robinson

解决方案

" Andrew Robinson" <是ne **** @ nospam.nospam>写道:

我有一些我正在更新的基类字段。我不需要使用
''base''修饰符来限定对我的字段的引用,但是它的使用是否会增加
的可读性?大多数人在C#中做了什么?

base.isValid = true;

isValid = true;

两者都有效。哪个更好?




''base''限定符用于访问基类的属性或

方法覆盖a虚拟财产或方法。由于字段是按照惯例,并且有充分的理由,通常是私有的,基数。''不会

能够在后代类中访问它们。 />

- Barry


将这些字段声明为受保护或我是否应该是不好的设计

使用我继承的类中的属性?


例如,我正在创建一系列类来处理与不同托运人的交易

交易。我的程序以相同的方式与这些

对象进行交互,但在内部,运输处理非常不同于处理器到处理器。我创建了一个公共基类,所以

至少每个''托运人'的外部属性是相同的。


有意义吗?


-


Andrew Robinson

" Barry Kelly" < BA *********** @ gmail.com>在消息中写道

新闻:bh ******************************** @ 4ax.com ...

" Andrew Robinson" <是ne **** @ nospam.nospam>写道:

我有一些我正在更新的基类字段。我不需要使用
''base''修饰符来限定对我的字段的引用,但它是否可以使用
添加
以便于阅读?大多数人在C#中做了什么?

base.isValid = true;

isValid = true;

两者都有效。哪个更好?



'base''限定符用于在覆盖虚拟属性或方法时访问基类的属性或
方法。由于字段是按照惯例,并且有充分理由,通常是私有的,基础。''不能在后代课程中访问它们。

- Barry



当然。这是重用代码和提供应用程序支持的方式

更容易


我希望这有助于

Galin Iliev [MCSD。 NET]
www.galcho.com


I have some base class fields that I am updating. I don''t need to use the
''base'' modifier to qualify the reference to my fields but does its use add
to readability? What do most people do in C#?

base.isValid = true;
or
isValid = true;

Both work. Which is better?

Thanks.

--

Andrew Robinson

解决方案

"Andrew Robinson" <ne****@nospam.nospam> wrote:

I have some base class fields that I am updating. I don''t need to use the
''base'' modifier to qualify the reference to my fields but does its use add
to readability? What do most people do in C#?

base.isValid = true;
or
isValid = true;

Both work. Which is better?



The ''base'' qualifier is for accessing the base class''s property or
method when overriding a virtual property or method. Since fields are,
by convention and for good reasons, usually private, ''base.'' would not
be able to access them in a descendant class.

-- Barry


Would it be poor design to declare those fields as protected or should I be
using properties from my inherited class?

For example, I am creating a series of classes that handle shipping
transactions with different shippers. My program interacts with these
objects in the same way but internally, the shipping is handled very
differently from processor to processor. I created a common base class so
that at least the external properties of each ''shipper'' are the same.

Make sense?

--

Andrew Robinson
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:bh********************************@4ax.com...

"Andrew Robinson" <ne****@nospam.nospam> wrote:

I have some base class fields that I am updating. I don''t need to use the
''base'' modifier to qualify the reference to my fields but does its use
add
to readability? What do most people do in C#?

base.isValid = true;
or
isValid = true;

Both work. Which is better?



The ''base'' qualifier is for accessing the base class''s property or
method when overriding a virtual property or method. Since fields are,
by convention and for good reasons, usually private, ''base.'' would not
be able to access them in a descendant class.

-- Barry



of course. this is the way to reuse code and make application support
much easier

I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com


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

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