C#太挑剔了? [英] C# is too nitpicky?

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

问题描述



为什么你可以在VB.net中这样做而不是(语法

相当于它)C#?:


Dim m as MessageBox

m.Show(" hello")


Why is it that you can do this in VB.net but not (the syntactical
equivilent of it in) C#?:

Dim m as MessageBox
m.Show("hello")

推荐答案

文章< qc ******************************** @ 4ax.com> ;, VeebeeGeeBees写道:
In article <qc********************************@4ax.com>, VeebeeGeeBees wrote:

为什么你可以在VB.net中这样做而不是(语法中它的等价)C#?:

Dim m as MessageBox
m.Show(" hello")

Why is it that you can do this in VB.net but not (the syntactical
equivilent of it in) C#?:

Dim m as MessageBox
m.Show("hello")




因为VB.NET太宽松了... MessageBox.Show是一个共享成员(静态
$ b#b中的b $ b。这意味着它与一个类的任何特定的

实例无关,但是这个类是自己的。结果是创建一个实例(使用new)来调用一个静态成员是不必要的。

在C#中,他们正确地通过不允许你进行这种区分来实现这一点。通过对象的实例调用

静态成员。我认为这很好,

因为它使代码更加明确。我的

诚实的意见中的VB.NET方式很邋and,并且可以使代码更难以阅读,因为你永远不能确定调用的方法是否共享。


-

Tom Shelton [MVP]



Because VB.NET is too lax... MessageBox.Show is a shared member (static
in C#). That means it is not associated with any particular instance of
a class, but with the class it''s self. The effect is that it is
unnecessary to create an instance (use new) to invoke a static member.
In C#, they correctly make this distinction by not allowing you to call
static members through instances of the object. I think this is good,
because it makes the code more explicit. The VB.NET way is sloppy in my
honest oppinion and can make the code harder to read since you can never
be sure if the method invoked is shared or not.

--
Tom Shelton [MVP]


2004年4月14日星期三13: 05:03 -0700,Tom Shelton< to *@mtogden.com>

写道:
On Wed, 14 Apr 2004 13:05:03 -0700, Tom Shelton <to*@mtogden.com>
wrote:
文章< qc ****** **************************@4ax.com> ;, VeebeeGeeBees写道:
In article <qc********************************@4ax.com>, VeebeeGeeBees wrote:

为什么会这样你可以在VB.net中做到这一点但是没有(语法中的等价物)C#?:

Dim m as MessageBox
m.Show(" hello" )

Why is it that you can do this in VB.net but not (the syntactical
equivilent of it in) C#?:

Dim m as MessageBox
m.Show("hello")



因为VB.NET太松散了... MessageBox.Show是一个共享成员(静态
在C#中)。这意味着它与一个类的任何特定实例都没有关联,但是对于类来说它是自己的。结果是创建一个实例(使用new)来调用一个静态成员是不必要的。
在C#中,他们通过不允许你通过静态成员调用来正确地做出这种区分。对象的实例。我认为这很好,
因为它使代码更加明确。我的
诚实的观点中的VB.NET方式很邋and,并且可以使代码更难阅读,因为你永远无法确定调用的方法是否共享。



Because VB.NET is too lax... MessageBox.Show is a shared member (static
in C#). That means it is not associated with any particular instance of
a class, but with the class it''s self. The effect is that it is
unnecessary to create an instance (use new) to invoke a static member.
In C#, they correctly make this distinction by not allowing you to call
static members through instances of the object. I think this is good,
because it makes the code more explicit. The VB.NET way is sloppy in my
honest oppinion and can make the code harder to read since you can never
be sure if the method invoked is shared or not.




当所有的Dot Net文档导致

时,你认为VB.Net中的Shared与C#中的static是相同的,这不是一件好事。 />
实际上他们的行为有所不同。能够实例化一个类型为MessageBox的新的
var更像是与purist类似。 OOP。 C#好像想要继承C ++糟糕实现的OOP功能。



Well its not a good thing when all of the Dot Net documentation leads
you to believe that Shared in VB.Net is the same as static in C#, when
in reality they behave differently. Being able to instantiate a new
var of type MessageBox is more in like with "purist" OOP. C# seems to
want to carry forward the poorly implemented OOP features of C++.


Tom,我很新但那有什么不同然后说

dim x as string

x.toUpper


你说你不能在C#中做到这一点?


我们不能告诉它这是一个共享类,因为没有New

构造函数吗?

你是对的,如果方法是

共享与否,有时很难读懂WRT读数。



" Tom Shelton" < to*@mtogden.com>在留言中写道

news:%2 **************** @ TK2MSFTNGP10.phx.gbl ...
Tom, I''m pretty new but how is that different then say
dim x as string
x.toUpper

are you saying you can''t do that in C#?

can''t we tell that it''s a shared class because of the absence of the New
constructor?

You''re right that it''s sometimes hard to read WRT reading if the method was
shared or not.


"Tom Shelton" <to*@mtogden.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
在文章中< qc ******************************** @ 4ax.com> ;, VeebeeGeeBees
In article <qc********************************@4ax.com>, VeebeeGeeBees



写道:


wrote:


为什么你可以在VB.net中这样做而不是(语法
相当于它) in)C#?:

Dim m as MessageBox
m.Show(" hello")

Why is it that you can do this in VB.net but not (the syntactical
equivilent of it in) C#?:

Dim m as MessageBox
m.Show("hello")



因为VB.NET太松懈了。 .. MessageBox.Show是一个共享成员(静态
在C#中)。这意味着它与一个类的任何特定实例都没有关联,但是对于类来说它是自己的。结果是创建一个实例(使用new)来调用一个静态成员是不必要的。
在C#中,他们通过不允许你通过静态成员调用来正确地做出这种区分。对象的实例。我认为这很好,
因为它使代码更加明确。我的
诚实的意见中的VB.NET方式很邋and,并且可以使代码更难阅读,因为你永远无法确定调用的方法是否共享。

- 汤姆谢尔顿[MVP]



Because VB.NET is too lax... MessageBox.Show is a shared member (static
in C#). That means it is not associated with any particular instance of
a class, but with the class it''s self. The effect is that it is
unnecessary to create an instance (use new) to invoke a static member.
In C#, they correctly make this distinction by not allowing you to call
static members through instances of the object. I think this is good,
because it makes the code more explicit. The VB.NET way is sloppy in my
honest oppinion and can make the code harder to read since you can never
be sure if the method invoked is shared or not.

--
Tom Shelton [MVP]



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

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