2d阵列 [英] 2d arrays

查看:108
本文介绍了2d阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本问题,被c#的类型系统搞糊涂了:


我正在制作一个日历编程,每天都有阵列,每天都是阵列

的活动。我想要这样的东西:


public struct活动

{

字符串名称;

字符串UID ;

}

私人ArrayList事件;

私人ArrayList(事件)天;


我我知道这是一个伪代码,所以我应该如何编写代码呢?如果需要

,天数可以是31个大小的静态阵列。


欢呼

dave

解决方案



" David Sobey" <毫安********** @ hotmail.com>在留言中写道

news:41 *********************** @ news.optusnet.com.a u ... < blockquote class =post_quotes>基本问题,混淆了c#的类型系统:

我正在制作一个日历编程,每天都有一个数组,每天都是一个数组
事件。我想要这样的东西:

公共结构事件
{
字符串名称;
字符串UID;
}
私有ArrayList事件;
private ArrayList(events)days;

我知道这是一个伪代码,所以我该如何编写代码呢?如果需要,日期可以是31个大小的静态数组。


好​​吧,有很多选择。您可以简单地使用Event [12,31]

数组或ArrayLists数组或ArrayLists的ArrayList,或者数组的
ArrayList。或者您可以使用哈希表。所有这些都取决于你如何获得信息。


你能提供更多关于你想要达到的信息吗?


欢呼
dave






随着有几个原因强烈建议不要使用arraylist存储

值类型(至少在c#中肯定)..请阅读有关对象拳击/

拆箱..


Nirosh。


" David Sobey" <毫安********** @ hotmail.com>在留言中写道

news:41 *********************** @ news.optusnet.com.a u ... < blockquote class =post_quotes>基本问题,混淆了c#的类型系统:

我正在制作一个日历编程,每天都有一个数组,每天都是一个数组
事件。我想要这样的东西:

公共结构事件
{
字符串名称;
字符串UID;
}
私有ArrayList事件;
private ArrayList(events)days;

我知道这是一个伪代码,所以我该如何编写代码呢?如果需要,日期可以是31个大小的静态阵列。

欢呼
dave


我基本上只是想为用户存储一个约会列表,所以我可以将它们发送到月历。每天的事件/约会次数

当然是任意的,但我想我可以将天数设置为31.我想b / b
认为数组列表是最好的但不是确定如何声明和

实例化它。这是对的:


公共结构事件

{

字符串名称;

字符串UID;

}

ArrayList day;

day [] month;


....


days = new ArrayList();

month = new day [31];


i应该尝试一下是吧?首先要吃晚餐... :)


感谢您的帮助

dave


basic question, confused by the type system of c#:

i''m making a calendar prog, with an array of days, each day being an array
of events. I want something like:

public struct Event
{
string name;
string UID;
}
private ArrayList events;
private ArrayList (events) days;

I''m aware this is kinda psuedo-code, so how should i really code this? If
necessary, the days can be a 31 sized static array.

cheers
dave

解决方案


"David Sobey" <ma**********@hotmail.com> wrote in message
news:41***********************@news.optusnet.com.a u...

basic question, confused by the type system of c#:

i''m making a calendar prog, with an array of days, each day being an array
of events. I want something like:

public struct Event
{
string name;
string UID;
}
private ArrayList events;
private ArrayList (events) days;

I''m aware this is kinda psuedo-code, so how should i really code this? If
necessary, the days can be a 31 sized static array.
Well, there are a number of choices. You could simply use an Event[12,31]
array or an array of ArrayLists or an ArrayList of ArrayLists, or an
ArrayList of arrays. Or you could use a hashtable. All depending on how you
want to access teh information.

Can you provide more information about what exactly you want to achieve?

cheers
dave



Hi,

With several reasons it is strongly advice not to use arraylist to store
value types (at least in c# for sure).. please read about object boxing /
unboxing..

Nirosh.

"David Sobey" <ma**********@hotmail.com> wrote in message
news:41***********************@news.optusnet.com.a u...

basic question, confused by the type system of c#:

i''m making a calendar prog, with an array of days, each day being an array
of events. I want something like:

public struct Event
{
string name;
string UID;
}
private ArrayList events;
private ArrayList (events) days;

I''m aware this is kinda psuedo-code, so how should i really code this? If
necessary, the days can be a 31 sized static array.

cheers
dave



i''m basically just trying to store a list of appointments for a user, so i
can send them to a monthly calendar. number of events/appointments per day
is arbitrary of course, but i suppose i could set number of days to 31. I
think an array of arrayLists is best but not sure how to declare and
instantiate it. Is this right:

public struct Event
{
string name;
string UID;
}
ArrayList day;
day[] month;

....

days = new ArrayList();
month = new day[31];

i should just try it huh? gotta have dinner first... :)

thanks for your help
dave


这篇关于2d阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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