C#struct构造函数如IntelliSense所示? (M'soft Rep PLease) [英] C# struct Constructors As Shown in IntelliSense? (M'soft Rep PLease)

查看:75
本文介绍了C#struct构造函数如IntelliSense所示? (M'soft Rep PLease)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在C#中创建结构并定义了参数化构造函数时,

IntelliSense编辑器仅显示参数化构造函数的语法
工具提示中的
,但不是默认构造函数似乎仍然存在
。如果这不是设计行为,它是一个错误还是我滥用我的

结构?

如果它是设计的,你能解释一下吗?我意识到关于构造函数的

结构的行为与类的行为不同,因为如果一个

类不会保留自动定义的默认构造函数/>
参数化构造函数由程序员定义。

结构构造函数选项的工具提示似乎遵循了类的规则?

我有点困惑,任何帮助都会非常感激!


-

彼得 - [MVP - 学术]

When a struct is created in C# and a parameterized constructor defined, the
IntelliSense editor shows only the syntax for the parameterized constructor
in tooltips, but not for the default constructor which appears to still
exist. If this is not designed behavior, is it a bug or am I misusing my
struct?
If it is by design, could you please explain? I realize the behavior of a
struct, as regards constructors, is different from that of classes in that a
class will not retain an automatically defined default constructor if a
parameterized constructor is defined by the programmer. The tooltip for
struct constructor options seems to be following the rules for a class?
I''m a bit confused, and any help getting straight would be much appreciated!

--
Peter - [MVP - Academic]

推荐答案

引用MSDN:


"声明

结构的默认(无参数)构造函数是错误的。总是提供一个默认构造函数来将struct

成员初始化为默认值。


要点是你不能覆盖什么默认构造函数。

框架是老板:)


干杯,


4空间


Peter van der Goes < p _ ********** @ mars.cox.net>在消息中写道

news:eA ************** @ TK2MSFTNGP09.phx.gbl ...
Quoting MSDN:

"It is an error to declare a default (parameterless) constructor for a
struct. A default constructor is always provided to initialize the struct
members to their default values."

The gist is that you can''t override what the default constructor does. The
framework is boss :)

Cheers,

4Space

"Peter van der Goes" <p_**********@mars.cox.net> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
创建结构时在C#和定义的参数化构造函数中,
IntelliSense编辑器仅显示工具提示中参数化
构造函数的语法,但不显示仍然存在的默认构造函数。如果这不是设计行为,它是一个错误还是我滥用我的
结构?
如果它是设计的,你能解释一下吗?我意识到构造函数的结构的行为与类的行为不同,因为如果程序员定义了
参数化构造函数,
a类将不会保留自动定义的默认构造函数。
struct构造函数选项的工具提示似乎遵循了类的规则?
我有点困惑,任何直接的帮助都会得到很多
赞赏!
- -
彼得 - [MVP - 学术]
When a struct is created in C# and a parameterized constructor defined, the IntelliSense editor shows only the syntax for the parameterized constructor in tooltips, but not for the default constructor which appears to still
exist. If this is not designed behavior, is it a bug or am I misusing my
struct?
If it is by design, could you please explain? I realize the behavior of a
struct, as regards constructors, is different from that of classes in that a class will not retain an automatically defined default constructor if a
parameterized constructor is defined by the programmer. The tooltip for
struct constructor options seems to be following the rules for a class?
I''m a bit confused, and any help getting straight would be much appreciated!
--
Peter - [MVP - Academic]



它应该显示系统用作
instantiator。


这是一个intellisense错误。它只是不承认它。


如果它对调用者可用它应该在intellisense上可见,

如果他们另有说法,他们会说话crrap


" Peter van der Goes" < p _ ********** @ mars.cox.net>在消息中写道

news:eA ************** @ TK2MSFTNGP09.phx.gbl ...
It SHOULD show the default one the system uses as its AVAILABLE to the
instantiator.

Its an intellisense bug. THey just dont admit it.

If its available to the caller it should be visible to on the intellisense,
if they say otherwise, theyre talkin crrap

"Peter van der Goes" <p_**********@mars.cox.net> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
创建结构时在C#和定义的参数化构造函数中,
IntelliSense编辑器仅显示工具提示中参数化
构造函数的语法,但不显示仍然存在的默认构造函数。如果这不是设计行为,它是一个错误还是我滥用我的
结构?
如果它是设计的,你能解释一下吗?我意识到构造函数的结构的行为与类的行为不同,因为如果程序员定义了
参数化构造函数,
a类将不会保留自动定义的默认构造函数。
struct构造函数选项的工具提示似乎遵循了类的规则?
我有点困惑,任何直接的帮助都会得到很多
赞赏!
- -
Peter - [MVP - 学术]
When a struct is created in C# and a parameterized constructor defined, the IntelliSense editor shows only the syntax for the parameterized constructor in tooltips, but not for the default constructor which appears to still
exist. If this is not designed behavior, is it a bug or am I misusing my
struct?
If it is by design, could you please explain? I realize the behavior of a
struct, as regards constructors, is different from that of classes in that a class will not retain an automatically defined default constructor if a
parameterized constructor is defined by the programmer. The tooltip for
struct constructor options seems to be following the rules for a class?
I''m a bit confused, and any help getting straight would be much appreciated!
--
Peter - [MVP - Academic]



你必须在param构造函数上初始化所有成员字段,但是intellisense

确实有一个错误,没有显示

实例化器的默认构造函数。


你可以有一行像...... br />

SomeStruct somethingStructure = new SomeStruct();


您没有定义系统对结构体执行的默认构造函数。但是

intelilsense应该在

以上的行中显示默认构造函数的可用性,但它没有。它说它不可用了。 BUG。

" Peter van der Goes" < p _ ********** @ mars.cox.net>在消息中写道

news:eA ************** @ TK2MSFTNGP09.phx.gbl ...
You must init ALL member fields on a param constructor, but intellisense
does have a bug on not displaying the default constructor for the
instantiator.

You CAN have a line like...

SomeStruct somethingStructure = new SomeStruct();

You dont define the default constructor the system does on structs. But
intelilsense SHOULD show the availability of the default constructor on the
above line but it doesnt. Its saying its not available yet it is. BUG.
"Peter van der Goes" <p_**********@mars.cox.net> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
创建结构时在C#和定义的参数化构造函数中,
IntelliSense编辑器仅显示工具提示中参数化
构造函数的语法,但不显示仍然存在的默认构造函数。如果这不是设计行为,它是一个错误还是我滥用我的
结构?
如果它是设计的,你能解释一下吗?我意识到构造函数的结构的行为与类的行为不同,因为如果程序员定义了
参数化构造函数,
a类将不会保留自动定义的默认构造函数。
struct构造函数选项的工具提示似乎遵循了类的规则?
我有点困惑,任何直接的帮助都会得到很多
赞赏!
- - 彼得 - [MVP - 学术]
When a struct is created in C# and a parameterized constructor defined, the IntelliSense editor shows only the syntax for the parameterized constructor in tooltips, but not for the default constructor which appears to still
exist. If this is not designed behavior, is it a bug or am I misusing my
struct?
If it is by design, could you please explain? I realize the behavior of a
struct, as regards constructors, is different from that of classes in that a class will not retain an automatically defined default constructor if a
parameterized constructor is defined by the programmer. The tooltip for
struct constructor options seems to be following the rules for a class?
I''m a bit confused, and any help getting straight would be much appreciated!
--
Peter - [MVP - Academic]



这篇关于C#struct构造函数如IntelliSense所示? (M'soft Rep PLease)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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