> So at this point there are not instances in the array.
I agree. It's a bit like decalring an array of integers and expecting them
to be initialized to a set of values other than 0.
Besides, when you create an array of CLASSA objects, you can also also store
objects that inherit from CLASSA in it. How does the framework know what
type you actually want to store?
If you want to initialize instances in an array you can use the following:
(it's VB, I'm not sure of the C# eqiuvelent is)
------------------------
Private Function GetArray() as CLASSA()
' Returns an array of 3 new instances of CLASS A
return new CLASSA() {new CLASSA(), new CLASSA(), new CLASSA()}
End Function
------------------------
Hope this helps,
Trev.
"Jan Tielens" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The following line only creates an array instance:
> CLASSA myclassarray = new CLASSA[5];
>
> So at this point there are not instances in the array. You'll have to add
> new instances to the array, and a the way you showed is a possibility.
>
>
> --
> Greetz,
> Jan
> __________________________________
> Read my weblog: http://weblogs.asp.net/jan
>
> "trinitypete" <(E-Mail Removed)> schreef in bericht
> news:0da501c3bb49$4a859120$(E-Mail Removed)...
> > Hi,
> >
> > This post is just to check that I am not missing a point
> > somewhere.
> >
> > I have a class say 'CLASSA' with a string member field
> > and associated property. I need an array of this class so
> > I execute the following code(C#)
> >
> > CLASSA myclassarray = new CLASSA[5];
> >
> > If I try to access the first elements memeber field
> > i.e. myclassarray.memberfield = "Hello";
> > I get an error saying object not set to instance of an
> > object. I thought this notation would create the complete
> > class array as the framework knows that each member of
> > the array is an instance of CLASSA.
> >
> > If I initialise each element of the class array as
> > follows:
> >
> > for ......
> > {
> > myclassarray[i] = new CLASSA();
> > }
> >
> > then I can access the member fields fine? Am I missing
> > something?
> >
> > Thanks in advance, Pete.
>
>