Re: C# Question
- From: "Ricks Place" <OFBGMail@xxxxxxxxx>
- To: <programmingblind@xxxxxxxxxxxxx>
- Date: Sun, 30 Mar 2008 14:55:05 -0400
Wow! Cool guys! Sorry Chris, looks like I was in Left field on this one.
Rick USA
----- Original Message -----
From: "Sina Bahram" <sbahram@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Sunday, March 30, 2008 2:42 PM
Subject: RE: C# Question
Once you know the size, you then have to assign something to your
reference,
using the size as the parameters to the constructor.
Currently, you just have an array reference pointing to null, so you'll
get
a null pointer exception.
But, you have to have that reference pointing to an array, given to you by
the constructor like so:
myArray = new MyClass[colSize][rowSize];
If you won't know the sizes ahead of time, then you can do one of a few
things, but the most popular solution will be to use a vector datatype
instead of an array datatype.
Arrays do not grow automatically.
Take care,
Sina
-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Chris
Hofstader
Sent: Sunday, March 30, 2008 2:27 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: C# Question
Hi,
I have a class which, for purposes of illustration, I'll call MyClass. I
want to declare a two dimensional array of this class so I can have a set
of
rows and columns within. I don't know the ultimate size of the array so I
declare it with empty brackets.
For instance:
MyArray[][] dataTable; // This compiles without error
but, in the code, if I state:
dataTable[0][0] = new MyClass();
I get an exception about a NULL assignment when the code is executed.
I had thought that .Net arrays declared without the "fixed" keyword would
grow dynamically and that the Array type overloaded the brackets to ensure
the sort of exception I'm getting doesn't happen.
Obviously, I'm doing something quite wrong but I'm having trouble finding
examples of C# arrays of anything more complex than int or String.
Please help.
Thanks,
cdh
Chris Hofstader
CUNY, BSO, ATG, Odds and Ends
email: cdh@xxxxxxxxxxxxx
Blog: http://www.blindconfidential.blogspot.com
Skype: BlindChristian
phone: 727-896-6393
__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind
__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind
__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind
- References:
- Programming is hard, let's go scripting
- From: Octavian Rasnita
- Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- From: Veli-Pekka Tätilä
- Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- From: Octavian Rasnita
- Re: Perl Pros and Cons: Syntax and Modules (Was: Larry Wall Talks, Perl and Lua)
- From: Veli-Pekka Tätilä
- Re: Perl Pros and Cons: Syntax and Modules (Was: Larry Wall Talks, Perl and Lua)
- From: Octavian Rasnita
- Re: Perl Pros and Cons: Syntax and Modules (Was: Larry Wall Talks, Perl and Lua)
- From: Veli-Pekka Tätilä
- Re: Perl Pros and Cons: Syntax and Modules (Was: Larry Wall Talks, Perl and Lua)
- From: Octavian Rasnita
- C# Question
- From: Chris Hofstader
- RE: C# Question
- From: Sina Bahram
Other related posts:
- » C# Question
- » RE: C# Question
- » Re: C# Question
- » Re: C# Question
- » RE: C# Question
- » Re: C# Question
- » RE: C# Question
- » RE: C# Question
- » RE: C# Question
- » Re: C# Question
- » RE: C# Question
- » Re: C# Question
- » RE: C# Question
- » RE: C# Question
- » Re: C# Question
- » C# Question - Marvin Hunkin
using the size as the parameters to the constructor.Currently, you just have an array reference pointing to null, so you'll get
a null pointer exception. But, you have to have that reference pointing to an array, given to you by the constructor like so: myArray = new MyClass[colSize][rowSize]; If you won't know the sizes ahead of time, then you can do one of a few things, but the most popular solution will be to use a vector datatype instead of an array datatype. Arrays do not grow automatically. Take care, Sina -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Chris Hofstader
Sent: Sunday, March 30, 2008 2:27 PM To: programmingblind@xxxxxxxxxxxxx Subject: C# Question Hi, I have a class which, for purposes of illustration, I'll call MyClass. Iwant to declare a two dimensional array of this class so I can have a set of
rows and columns within. I don't know the ultimate size of the array so I declare it with empty brackets. For instance: MyArray[][] dataTable; // This compiles without error but, in the code, if I state: dataTable[0][0] = new MyClass(); I get an exception about a NULL assignment when the code is executed. I had thought that .Net arrays declared without the "fixed" keyword would grow dynamically and that the Array type overloaded the brackets to ensure the sort of exception I'm getting doesn't happen. Obviously, I'm doing something quite wrong but I'm having trouble finding examples of C# arrays of anything more complex than int or String. Please help. Thanks, cdh Chris Hofstader CUNY, BSO, ATG, Odds and Ends email: cdh@xxxxxxxxxxxxx Blog: http://www.blindconfidential.blogspot.com Skype: BlindChristian phone: 727-896-6393 __________ View the list's information and change your settings at http://www.freelists.org/list/programmingblind __________ View the list's information and change your settings at http://www.freelists.org/list/programmingblind
- Programming is hard, let's go scripting
- From: Octavian Rasnita
- Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- From: Veli-Pekka Tätilä
- Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- From: Octavian Rasnita
- Re: Perl Pros and Cons: Syntax and Modules (Was: Larry Wall Talks, Perl and Lua)
- From: Veli-Pekka Tätilä
- Re: Perl Pros and Cons: Syntax and Modules (Was: Larry Wall Talks, Perl and Lua)
- From: Octavian Rasnita
- Re: Perl Pros and Cons: Syntax and Modules (Was: Larry Wall Talks, Perl and Lua)
- From: Veli-Pekka Tätilä
- Re: Perl Pros and Cons: Syntax and Modules (Was: Larry Wall Talks, Perl and Lua)
- From: Octavian Rasnita
- C# Question
- From: Chris Hofstader
- RE: C# Question
- From: Sina Bahram