Bill,

Thanks for your reply; I've tried this syntax and unfortunately it is not
working w/ classes. (It is fine to declare integer arrays), but since I want to
pass a listview reference, I get an error saying that there is no way to convert
a ListView to CMyClass.

Right now this is what I do:

   m_oMyObjs = new CMyClass[2]; // create array of objects
   m_oMyObjs[0] = new CMyClass ( lvP1 );
   m_oMyObjs[1] = new CMyClass ( lvP2 );

This is not the solution I'm looking for but as I'm also leaning C#, this will
work for now.

Thanks again,
Gyorgy

-----Original Message-----
From: dotnet discussion [mailto:[EMAIL PROTECTED]]On Behalf Of
Bill Schmidt
Sent: Saturday, May 18, 2002 14:43
To: [EMAIL PROTECTED]
Subject: Re: How to initialize object arrays in C#?


Gyorgy,

I'm new to C#, but I believe that the proper syntax is:
    m_oMyObjs = new CMyClass[] {lvP1, lvP2};
just as for an array of int or char.  This syntax uses the single-parameter
constructor that you included in your example class definition.  The number
of elements in the array is determined by the number of elements in the
initialization list.

Bill

On Sat, 18 May 2002 13:35:02 -0500, =?iso-8859-1?Q?Gy=F6rgy_Boz=F3ki?=
<[EMAIL PROTECTED]> wrote:

>Hi guys,
>
>Here is what I'd like to do (in C#):
>
>I have a class CMyClass, it looks like this:
>
> public class CMyClass
>  {
>    #region Private members
>    private ListView m_lvP; // listview associated w/ the class
>    private ColumnHeader m_chA; // column header
>    private ColumnHeader m_chB; // column header
>    private ColumnHeader m_chC; // column header
>    #endregion
>
>    #region Public members
>    /// <summary>
>    /// Constructor
>    /// </summary>
>    public CPanel ( ListView lvP )
>     {
>       if ( lvP != null ) // the listview reference cannot be NULL
>        {
>         m_lvP = lvP;
>
>         m_chName = new ColumnHeader ();
>         m_chSize = new ColumnHeader ();
>         m_chDate = new ColumnHeader ();
>
>         /// ...
>        }
>     }
>    #endregion
>  }
>
>In a form, I want to have two instances of this class, as a two-element
array of
>CMyClass type, so I make a declaration:
>
>public class frmMain : System.Windows.Forms.Form
> {
>  private CMyClass[] m_oMyObjs;
>  private System.Windows.Forms.ListView lvP1; // this listview should be
>associated w/ m_oMyObjs
>
>  public frmMain ()
>   {
>    /// ...
>    m_oMyObjs = new CMyClass[2]; // how to make the
declaration/initialization
>to be able to pass the listview?
>   }
> }
>
>
>So, how can I pass the listview (which is initialized correctly) to the
class
>through the constructor when declaring an array? If possible, I'd like to
avoid
>having a get/set property for passing the listview, since it cannot change
after
>the CMyClass object is created and there is no need to access it in any
way. I'm
>not able to figure out the correct syntax (if it is possible) to do this.
>
>Thanks for the help,
>Gyorgy Bozoki
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to