考虑二维数组作为对象? [英] consider a 2 dimension array as an object?

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

问题描述

你好,
我们可以将二维数组视为对象吗?我想要一个成员为2维数组的arraylist.

有可能吗?

请帮帮我.

在此先感谢

Hello,
Can we consider a Two dimension array as an object? I want to have an arraylist which members are 2 dimension arrays.

Is it possible?

Please help me.

Thanks in advance

推荐答案

所有内容,绝对所有内容都是对象,即使是非盒装常量1.类和结构类型的所有对象,基本类型和枚举的所有数组和盒装形式.

同样,委托和事件实例是某些隐式定义的类的对象.如果在这些实例上使用GetType()和Reflection,则可以找到答案.

这是一件更加微妙的事情.请查看我过去的回答和最近的文章:
对代表的困惑 [动态方法调度器 [其中" '我们是否可以找到开源的c#树结构 [
Everything, absolutely everything is an object, even non-boxed constant 1. In a wider sense of this word, objects in the sense of OOP are all objects of class and structure types, all arrays and boxed forms of primitive types and enumerations.

Also, delegate and event instances are objects of some implicitly defined classes. You can find it out if you use GetType() and Reflection on those instances.

This is much more delicate matter. Please see my past answer and recent article:
Confusion about delegates[^],
Dynamic Method Dispatcher[^].

Now. Never use ArrayList! This class is made obsolete with v.2.0 when generics were introduced. Use System.Collections.Generic.List instead. The element type can be absolutely anything. Even the same type as the list itself, which makes a tree structure.
(See my recent answer: where''re we can find a open source c# tree structure[^].)

This should answer your question.

—SA


是的,您可以这样做.但我建议您使用通用列表,而不要使用arraylist.
Yes you can do. But I would suggest you to have a generic list instead of arraylist.


1.甚至原始数据类型都是.Net中的对象.如果它们是值类型,则将它们区别对待,但它们仍然是对象.

2.在许多情况下,数组不是一个好的选择,因为您必须预先设置其尺寸,但是仍然可以将它们放入列表中.为什么不简单尝试一下呢?

3.即使它们是值类型或不是对象,您仍然可以将它们包装在一个对象中,然后将它们放在列表中.
1. Even primitive data types are objects in .Net. If they are value types they are treated a little differently, but they are still objects.

2. Arrays are not a good choice in many cases because you must set their dimensions beforehand, but still you might put them into lists. Why don''t you simply try it out?

3. Even if they were value types or were no objects, you could still wrap them up in an object and then put those in your list.


这篇关于考虑二维数组作为对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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