为什么C#中没有数组属性。 [英] Why no array property in C#.
问题描述
我已经使用Delphi几年了,现在使用的是Delphi8和VC#。我刚刚在VC#2.0上预览过
。
我想知道为什么没有数组属性?虽然有VB $ B $ VB $,VB网站,Delphi.net和IL。
例如,在Delphi,我可以有
tStringsObject.strings [i];
tStringsObject.values [''something''];
tstringsObject.keys [b];
数组属性看起来像一个数组,但不一定需要数据
缓冲区。
数组属性对写入非常方便/布线组件和
包装类和数据。
在C#中,你只能拥有一个一个类的索引器。现在,当我将一些Delphi代码或Delphi 8代码移植到C#时,我必须将
接口更改为方法。
我曾联系过Microsoft C#团队,他们说很久以前他们选择了
不支持阵列属性。 在这种情况下,我们选择简单优于
灵活性。
我明白属性和数组属性基本上是
成员函数类。发布的属性可以出现在
对象检查器上,以便您在设计时定义数组项目的集合
属性。
没有数组属性,我必须编写代码来初始化项目
的集合。这对RAD来说并不好。
我从一个为期2天的网络研讨会上听到,微软并不担心它在桌面应用程序中的主导地位,在服务器市场上,微软对Linux的关注度非常高。 Dot Net和C#主要关注服务器上的
,其中RAD开发不如桌面上那么吸引人。
我认为这是关键因素之一为什么MS C#团队不想实现
实现数组属性。
最好的问候
Dingdang >
丁当写道:
数组属性看起来像一个数组,但不一定需要数据
缓冲区。
如果没有数组属性,我必须编写代码来初始化集合中的项目。
不,你不是。将您的属性定义为内部
定义的类的实例。为此定义索引器。
//警告:未经测试的代码。
class StringsObject
{
private class SO_string
{
public string this [](int i){....}
}
公共SO_string字符串
{
得到{.....}
}
}
-
真相,
James Curran [MVP]
www.NJTheater.com (专业)
www.NovelTheory.com (个人)
James Curran写道:
丁当写道:
数组属性看起来像一个数组,但不一定需要数据缓冲区。
没有数组属性,我必须编写代码来初始化项目
收藏。
不,你不。将您的属性定义为内部定义的类的实例。为此定义索引器。
//警告:未经测试的代码。
类StringsObject
{私有类SO_string
{
公共字符串this [](int i){....}
}
公共SO_string字符串
{
get {.....}
}
}
Hm。那很有意思!你能放一段工作代码吗?我只想了解
如何使用它......我还是有点新手;)
谢谢
Andrey
> Dot Net和C#主要关注服务器上的,其中RAD开发不如桌面上那么吸引人。
谁说的?
-
William Stacey,MVP
I have been using Delphi for a few years, now using Delphi8 and VC#. I
just had a preview on VC# 2.0.
I was wondering why there is no array property? While there is in
VB.net, Delphi.net and IL.
For example, in Delphi, I could have
tStringsObject.strings[i];
tStringsObject.values[''something''];
tstringsObject.keys[b];
Array property looks like an array, but does not necessarily need data
buffers.
Array property is really handy for writing/wiring components and
wrapping classes and data.
In C#, you could only have indexer which one for one class. Now when I
port some Delphi code or Delphi 8 codes to C#, I have to change the
interfaces to methods.
I had contacted the Microsoft C# team, and they said they had chose
not to support array property long time ago. "We chose simplicity over
flexibility in this case."
I understand that properties and array properties are essentially
member functions of a class. Published properties could appear on the
object inspector for you to define a collection of items of an array
property at design time.
Without array property, I have to then write codes to initialize items
of a collection. This is not good for RAD.
I heard from a 2-day dot Net seminar, Microsoft is not worried about
its dominant position on desktop applications, Microsoft is much
concerned by Linux on the server markets. Dot Net and C# mostly focus
on server, on which RAD development is not as appeal as on desktop.
I think this is one of the key factors why MS C# team did not want to
implement array property.
Best regards
Dingdang
Ding Dang wrote:
Array property looks like an array, but does not necessarily need data
buffers. Without array property, I have to then write codes to initialize items
of a collection.
No you don''t. Define you property as a instance of an internally
defined class. Define an indexer for that.
// Warning : untested code.
class StringsObject
{
private class SO_string
{
public string this[](int i) { ....}
}
public SO_string strings
{
get { .....}
}
}
--
Truth,
James Curran [MVP]
www.NJTheater.com (Professional)
www.NovelTheory.com (Personal)
James Curran wrote:
Ding Dang wrote:Array property looks like an array, but does not necessarily need data
buffers.
Without array property, I have to then write codes to initialize items
of a collection.
No you don''t. Define you property as a instance of an internally
defined class. Define an indexer for that.
// Warning : untested code.
class StringsObject
{
private class SO_string
{
public string this[](int i) { ....}
}
public SO_string strings
{
get { .....}
}
}
Hm. that''s interesting! Can you put a working piece of code? I just want to understand how exactly
to use it... I am still kinda newbie ;)
Thank you
Andrey
> Dot Net and C# mostly focuson server, on which RAD development is not as appeal as on desktop.
Who said that?
--
William Stacey, MVP
这篇关于为什么C#中没有数组属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!