473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

2d arrays

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
Nov 16 '05 #1
9 8380

"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

Nov 16 '05 #2
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

Nov 16 '05 #3
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
Nov 16 '05 #4
how on earth to i declare and define a static array of ArrayLists? And how
would i pass this to a function. I simply cannot get my code to work:

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

....
public void SetEvents(ArrayList[] list)
{
month = new ArrayList[31];
month = list.Clone();
}

It INSISTS that month is an ArrayList, which it is NOT. It's supposed to be
a static array.
Nov 16 '05 #5
I really think your best bet would be to look at Hashtables, keyed by
DateTime, pointing maybe to ArrayLists of appointments.

As for your ArrayList[] concept, the ArrayList[] itself stands for an array
of ArrayLists, or more precisely, ArrayList references. You would have to
initialize every one of the members, like:

ArrayList[] month = new ArrayList[31];

for (int day = 0; day < 31; day++)
month[day] = new ArrayList();

But as I don't think you'd like to instantiate thousands of ArrayLists in
your calendar, I'd recommend something like the following:

Hashtable calendar = new Hashtable();

ArrayList GetAppointments(DateTime date)
{
date = date.Date; // strip the time part, if any...

ArrayList appointments = calendar[date] as ArrayList;

if (appointments == null)
{
appointments = new ArrayList();
calendar[date] = appointments;
}

return appointments;
}

If you need any more help, you can also contact me directly (remove the blah
from my address)

HTH,
Stefan

"David Sobey" <ma**********@hotmail.com> wrote in message
news:41***********************@news.optusnet.com.a u...
how on earth to i declare and define a static array of ArrayLists? And how
would i pass this to a function. I simply cannot get my code to work:

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

...
public void SetEvents(ArrayList[] list)
{
month = new ArrayList[31];
month = list.Clone();
}

It INSISTS that month is an ArrayList, which it is NOT. It's supposed to
be a static array.

Nov 16 '05 #6

"David Sobey" <ma**********@hotmail.com> wrote in message
news:41***********************@news.optusnet.com.a u...
how on earth to i declare and define a static array of ArrayLists? And how
would i pass this to a function. I simply cannot get my code to work:

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

...
public void SetEvents(ArrayList[] list)
{
month = new ArrayList[31];
month = list.Clone();
}

It INSISTS that month is an ArrayList, which it is NOT. It's supposed to
be a static array.


Month is an array, in this particualar circumstance. The line
ArrayList[] month;
Creates a variable named month that is typed an array of the class
ArrayList. I don't quite understand what you mean by it insisting that month
is an ArrayList. Every test I can come up with doesn't seem to fail. Infact
the only problem I can find with your code is that the call to list.Clone()
needs to be cast to ArrayList[].

Could you provide a short but complete[1] example of the issue?

1. http://www.yoda.arachsys.com/csharp/complete.html
Nov 16 '05 #7
actually i think you're right, just the way i was using was a bit ignorant.
thanks for your help though. i've been programming haskell lately so it's a
bit tricky, seeing the type system is so different.

cheers
dave

--
"Aristotle said that some people were
only fit to be slaves. I do not
contradict him. But I reject slavery
becase I see no people fit to be masters"
C.S Lewis
Nov 16 '05 #8

"David Sobey" <ma**********@hotmail.com> wrote in message
news:41***********************@news.optusnet.com.a u...
actually i think you're right, just the way i was using was a bit
ignorant. thanks for your help though. i've been programming haskell
lately so it's a bit tricky, seeing the type system is so different.


Yes, I can certainly see that,;). Fundamentally different type systems can
be hard to overcome.

I hope you've been able to fix your problem.
Nov 16 '05 #9
"Aristotle said that some people were
only fit to be slaves. I do not
contradict him. But I reject slavery
becase I see no people fit to be masters"
C.S Lewis

I knew Aristotle was a brainy guy but 'gawd!', this is too much!.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.