473,406 Members | 2,371 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,406 software developers and data experts.

Just started c#, question about member creation

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.
Nov 25 '07 #1
3 982
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<Tor IList<T(and use a List<Tin the
_Internal field)? You would get much more type-safety that way.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Phil Da Lick!" <ph***********@spammerskissmyarse.hotmail.comwro te in
message news:ev**************@TK2MSFTNGP06.phx.gbl...
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.
Nov 25 '07 #2
Nicholas Paldino [.NET/C# MVP] wrote:
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<Tor IList<T(and use a List<Tin 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.
Nov 25 '07 #3
Phil Da Lick! <ph***********@spammerskissmyarse.hotmail.comwrote :

<snip>
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Nov 25 '07 #4

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

Similar topics

1
by: Tony Johansson | last post by:
Hello! I have this wrapper class Integer below that I use when testing operator overloading. A book that I read say that the expression Integer i; i+5 is translated to operator+(i,5) using the...
11
by: cfchou | last post by:
hi, all, i'm reading ch.20 -smart pointers- of . and i'm tring the trule.hpp test. but there's something different than i expect, and i found that's about temp object. so i simplified the...
9
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
25
by: Tim | last post by:
Dear Developers, Firstly, I'm not sure where this post should go so I apologise if this is in the wrong group or area. I'm currently interviewing for a vb.net developer who doesn't mind...
7
by: Becci | last post by:
Is there a way to know, when we get an "ONChanged" event from the filesystemwatcher, what actually changed, file, last access, last write, etc? Seems they are all bundled into the one event?
36
by: peter.mosley | last post by:
I am trying to learn GUI programming in Python, but have to confess I am finding it difficult. I am not an experienced programmer - just someone who from time to time writes small programs for...
8
by: Narf the Mouse | last post by:
I'm currently working on a roguelike as an excercise in learning c++. Anyway, I've set up a script parser to check a text file to find out how many races there are, then dynamically alocate an...
18
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two...
7
by: v4vijayakumar | last post by:
Is it possible to implement member object's virtual functions, in the containing class? If not, is it possible to simulate this behavior? ex: class test { protected: virtual void fun() = 0;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.