Just started c#, question about member creation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Da Lick!

    #1

    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(_Interna l);
    }
    }
    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.
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Just started c#, question about member creation

    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]
    - mvp@spam.guard. caspershouse.co m



    "Phil Da Lick!" <phil_the_lick@ spammerskissmya rse.hotmail.com wrote in
    message news:evHE012LIH A.4688@TK2MSFTN GP06.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(_Interna l);
    }
    }
    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.

    Comment

    • Phil Da Lick!

      #3
      Re: Just started c#, question about member creation

      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.

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Just started c#, question about member creation

        Phil Da Lick! <phil_the_lick@ spammerskissmya rse.hotmail.com wrote:

        <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 - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        World class .NET training in the UK: http://iterativetraining.co.uk

        Comment

        Working...