c#的最佳编码风格(第3版) [英] Best coding style for c#( 3rd)

查看:31
本文介绍了c#的最佳编码风格(第3版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个从System.Windows.Forms.Form派生的输入窗口。


我使用的只是一个属性inputWindow.Message。


但是System.Windows.Forms.Form有很多属性,函数,

evnets。


所以我想要隐藏所有东西除了一个属性

" inputWindow.Message" ;.


我该怎么做?

解决方案

kiplring ha scritto:


[cut]

我该怎么做?




你可以写一个包装类。


再见,

Giulio - Italia


我会说你不能因为没有办法改变你的基类

属性,除非你可以重写基类。只要留在那里就可以了。

不要使用它。


如果你设法或某人可以教你怎么做,那么请发电子邮件

我。谢谢


chanmm


" kiplring" <き******** @ hotmail.com>在消息中写道

news:11 ********************* @ 75g2000cwc.googlegrou ps.com ...

我创建了一个从System.Windows.Forms.Form派生的输入窗口。

我使用的只是一个属性inputWindow.Message。

但是系统.Windows.Forms.Form有很多属性,功能,evnets。

所以我想隐藏除了一个属性之外的所有东西
inputWindow.Message。

我怎么能这样做?



kiplring写道:

我做了一个从System.Windows.Forms.Form派生的输入窗口。

我使用的只是一个属性inputWindow.Message。

但是System.Windows.Forms.Form有这么多的属性,功能,

所以我想隐藏除了一个属性之外的所有东西
inputWindow.Message。
我该怎么办?




嗨Kiplring,


只是_one_财产?你不只是使用Show()或ShowDialog()

方法吗?

你可以做的是:

///

公共类InputWindowForm

{

私人表格_actualForm;


public InputWindowForm()

{

_actualForm = new Form();

}


公共字符串消息

{

get {return" foo" ;; }

}

}

///


并为什么提供包装函数/属性你需要。然而,恕我直言,我没有真正明白这一点。您可能会发现您开始需要越来越多的属性/方法,并且您将添加相当多的

包装函数。它也违背了继承的目的。


- 汤姆斯宾克


I made a input window derived from System.Windows.Forms.Form.

What I use is just one property "inputWindow.Message".

But System.Windows.Forms.Form has so many properties, functions,
evnets.

So I want to hide all things except the one property
"inputWindow.Message".

How can I do it?

解决方案

kiplring ha scritto:

[cut]

How can I do it?



You can write a wrapper class.

Bye,
Giulio - Italia


I will say you can''t because there is no way to change your base class
properties unless you can rewrite the base class. Just leave it there and
don''t use it.

If you manage to or someone can teach you how to do it then please do email
me. Thanks

chanmm

"kiplring" <ki********@hotmail.com> wrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...

I made a input window derived from System.Windows.Forms.Form.

What I use is just one property "inputWindow.Message".

But System.Windows.Forms.Form has so many properties, functions,
evnets.

So I want to hide all things except the one property
"inputWindow.Message".

How can I do it?



kiplring wrote:

I made a input window derived from System.Windows.Forms.Form.

What I use is just one property "inputWindow.Message".

But System.Windows.Forms.Form has so many properties, functions,
evnets.

So I want to hide all things except the one property
"inputWindow.Message".

How can I do it?



Hi Kiplring,

Just _one_ property? Do you not just use the Show() or ShowDialog()
methods?

What you could do is something like:

///
public class InputWindowForm
{
private Form _actualForm;

public InputWindowForm ()
{
_actualForm = new Form();
}

public string Message
{
get { return "foo"; }
}
}
///

And provide wrapper functions/properties to what you need. IMHO, however, I
don''t really see the point. You''ll probably find you''re starting to need
more and more properties/methods and you''ll be adding quite a lot of
wrapper functions. It also defeats the purpose of inheritance.

-- Tom Spink


这篇关于c#的最佳编码风格(第3版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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