且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将参数传递给C#中的属性?

更新时间:2022-04-07 00:19:02

Prachi Dimble< pr **** @ eximiuus.com>写道:
Prachi Dimble <pr****@eximiuus.com> wrote:
在vb.Net中,可以将参数传递给属性。如何在c#中实现它?下面给出了将参数传递给
属性getter和setter的vb.net代码..
In vb.Net one can pass arguments to properties. How does one achieve
it in c#? Given below is the vb.net code for passing arguments to
property getters and setters..




在C#中,你只能将参数传递给被调用的特殊属性

索引器。你需要让你的房产成为你班级的索引。


-

Jon Skeet - < sk *** @ pobox.com&gt ;
http://www.pobox.com/~skeet

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



In C#, you can only pass parameters to special properties called
indexers. You''ll need to make your property an indexer for your class.

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




" Jon Skeet [C#MVP ]&QUOT; &LT; SK *** @ pobox.com&GT;在消息中写道

新闻:MP ************************ @ msnews.microsoft.c om ...

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Prachi Dimble< pr **** @ eximiuus.com>写道:
Prachi Dimble <pr****@eximiuus.com> wrote:
在vb.Net中,可以将参数传递给属性。如何在c#中实现它?下面给出了用于将参数传递给
属性getter和setter的vb.net代码..
In vb.Net one can pass arguments to properties. How does one achieve
it in c#? Given below is the vb.net code for passing arguments to
property getters and setters..



在C#中,只能将参数传递给名为
的特殊属性索引。您需要让您的酒店成为您班级的索引器。

-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件



In C#, you can only pass parameters to special properties called
indexers. You''ll need to make your property an indexer for your class.

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




我认为C#对于这个索引器来说非常麻烦。我想知道为什么

Hejlsberg等人决定采用这种复杂性,当Delphi以VB.NET的方式运行参数化属性。他们坚持

已经知道更好....


- Michael S



I think C# is quite cumbersome with this indexer-thingy. I wonder why
Hejlsberg et al decided do go for such complexity, when Delphi sported
parameterized properties in just the way VB.NET does stuff. They shoulod
have known better....

- Michael S


"迈克尔S&QUOT; &LT; a@b.c> écritdansle message de news:

ua ************* @ TK2MSFTNGP12.phx.gbl ...
"Michael S" <a@b.c> a écrit dans le message de news:
ua*************@TK2MSFTNGP12.phx.gbl...
我觉得C#对于这个索引器来说非常麻烦。我想知道为什么Hejlsberg等人决定采用这种复杂性,当Delphi以VB.NET的方式运行参数化属性时。他们已经知道了更好....
I think C# is quite cumbersome with this indexer-thingy. I wonder why
Hejlsberg et al decided do go for such complexity, when Delphi sported
parameterized properties in just the way VB.NET does stuff. They shoulod
have known better....




这就是为什么Delphi 2005提供的Delphi for .NET(以及C#)是

这么好的主意。 Delphi在***OO框架.NET中的所有遗产。


Joanna


-

Joanna Carter

顾问软件工程师



Which is why Delphi for .NET as provided (along with C#) by Delphi 2005 is
such a good idea. All the heritage of Delphi in the best OO framework .NET.

Joanna

--
Joanna Carter
Consultant Software Engineer