Just started c#, question about member creation

  • Thread starter Thread starter Phil Da Lick!
  • Start date Start date
P

Phil Da Lick!

Hi all,

Creating a class library with an object that needs to expose a list of
other objects. Using vs 2008/.NET 3.5.

So far got this:

public class MyClass
{
private ArrayList _Internal=new ArrayList();

public ArrayList List
{
get
{
return(_Internal);
}
}
public MyClass()
{
}
}

My questions:
1. Is it correct to create the _Internal object in its declaration as
shown, or should the call to new ArrayList() be in the constructor?
2. Am I right in assuming that calling MyClass.List will in effect
return a pointer to the list?

Cheers,

Phil.
 
Phil,

I wouldn't say it is more correct or less correct to instantiate the
array list in the constructor or the declaration. They will result in the
same thing, the same semantics (for the most part).

Yes, the List property will return the reference to the ArrayList.

Just curious? If your lists are holdling an object of just one type,
then why not expose a List<T> or IList<T> (and use a List<T> in the
_Internal field)? You would get much more type-safety that way.
 
Nicholas said:
Phil,

I wouldn't say it is more correct or less correct to instantiate the
array list in the constructor or the declaration. They will result in
the same thing, the same semantics (for the most part).

Yes, the List property will return the reference to the ArrayList.

Just curious? If your lists are holdling an object of just one type,
then why not expose a List<T> or IList<T> (and use a List<T> in the
_Internal field)? You would get much more type-safety that way.

Haven't actually decided whether it will be one type in the list, may do
a base class/multi derived thingy yet.

Anyone got any info on when VS2k8 will be available for purchase? I'm
currently using the trial version, which I like very much.

Thanks for the swift response!

Phil.
 
Anyone got any info on when VS2k8 will be available for purchase? I'm
currently using the trial version, which I like very much.

It's been released for MSDN subscribers, or the Express edition is
freely available now. I don't know when Standard/Pro will be available
as a standalone purchase.
 
Back
Top