存储数组的属性??? [英] Property to store an Array???

查看:50
本文介绍了存储数组的属性???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在如何在物业中存储和访问数组的示例

Dave

Is there an example of how to store and access an array in a Property

Dave

推荐答案


df********@hotmail.com 写道:
是否有如何在Property中存储和访问数组的示例
Is there an example of how to store and access an array in a Property



不确定你的意思。如果你的意思是属于一个数组的属性,那么

工作正常:


private int [] intArray = new int [20];

public int [] IntArray

{

get {return intArray; }

set {intArray = value; }

}


//然后......


myobject m = new myobject();

int [] curArray = m.IntArray;


那是你想要做的吗?


matt



Not sure what you mean. If you mean a property that IS an array, it
works fine:

private int[] intArray = new int[20];
public int[] IntArray
{
get { return intArray; }
set { intArray = value; }
}

// and then...

myobject m = new myobject();
int[] curArray = m.IntArray;

Is that what you were trying to do?

matt


我正在存储文件名。可能是1或1000.我刚刚阅读了一篇关于索引器的文章。哪个更好用?

I am storing file names. The may be 1 or 1000. I was just reading an
article about indexers. Whould that work better?



df********@hotmail.com 写道:
我正在存储文件名。可能是1或1000.我刚刚阅读了一篇关于索引器的文章。这样做会更好吗?
I am storing file names. The may be 1 or 1000. I was just reading an
article about indexers. Whould that work better?




和大多数事情一样,这取决于你。您可以使用ArrayList

(1.1)

或通用数组(2.0)来存储您的数据,然后使用

索引器返回它。

您可以简单地覆盖操作符[]并返回您想要的任何内容。

什么

您真正需要决定的是您提供的内容进入。 C#

提供

大量的语法糖方法,让事情看起来容易到底

用户。

那个并不意味着他们中的任何一个都是更好的比什么都好。


马特



As with most things, it really is up to you. You could use an ArrayList
(1.1)
or a generic array (2.0) to store your data and then return it using an
indexer.
You could simply override the operator[] and return whatever you want.
What
you really need to decide is what you are providing access to. C#
provides
lots of syntactic sugar methods for making things look easy to the end
user.
That doesn''t mean any of them are any "better" than anything else.

Matt


这篇关于存储数组的属性???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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