how to Create array of objects

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: John Haigh (john_at_shelluser.net)
Date: 04/05/04


Date: Mon, 5 Apr 2004 19:10:05 -0400

I have the need to create an array of objects. Now this sound fairly trivial
but I can't figure this out.

I have one class called PostingObjectService that has a method GetPostings
where the problem begins (class is below) where in the foreach loop I need
to add Postings to the PostingObject[] array which will be returned by this
method. Then I have the class PostingObject where I am unsure how to create
the array or add to the array of PostingObjects.

Please help.

Thanks, John

PostingObjectService.cs
using System;
using System.Collections;
using Microsoft.ContentManagement.Publishing;

namespace test.CMS.library
{
 /// <summary>
 /// Summary description for PostingService.
 /// </summary>
 public class PostingObjectService
 {
  public PostingObjectService()
  {
   //
   // TODO: Add constructor logic here
   //
  }
 public PostingObject[] GetPostings(string sChannelGuid, DateTime
dtStartDate, DateTime dtEndDate)
  {
   PostingObject[] oReturnedCol = null;

   //Get the current channel (News channel) based on the passed GUID to the
method
   Channel aChannel = CMSAPI.GetChannel(sChannelGuid);

   PostingCollection oPostCol = aChannel.Postings;
   oPostCol.SortByStartDate( false );

   foreach ( Posting oPost in oPostCol )
   {
    // If month has changed
    PostingObject oNewMonth = new PostingObject( dtStartDate, dtEndDate );
    //oNewMonth.objPosting[0].
    //oNewMonth
    //oPost.StartDate
   }
   return oReturnedCol;

  }
 }
}

PostingObject.cs
using System;
using System.Collections;
using Microsoft.ContentManagement.Publishing;

namespace test.CMS.library
{
 /// <summary>
 /// Summary description for PostingObject.
 /// </summary>
 public class PostingObject
 {

  #region Instance variables
  internal Posting[] objPosting = null;

  #endregion

  #region Constructor
  public PostingObject()
  {
  }

  // start date
  public PostingObject(DateTime StartDate)
  {
// Do I add to the array of Postings here?
   objPosting.
  }

  // start date, end date
  public PostingObject(DateTime StartDate, DateTime EndDate)
  {
   // Do I add to the array of Postings here?
  }

  #endregion

  public String StartDate
  {
   get
   {
    if(objPosting != null)
    {
     return objPosting.StartDate.ToString();
    }
    else
    {
     return null;
    }

   }
  }

  public String EndDate
  {
   get
   {
    if(objPosting != null)
    {
     return objPosting.ToString();
    }
    else
    {
     return null;
    }

   }
  }

 } //END class
}// END namespace



Relevant Pages

  • Re: how to Create array of objects
    ... Is it true that Postings and the PostingObject[] will not be 1:1? ... dtStartDate, DateTime dtEndDate) ... If PostingObjectis 1:1 with Postings then you can dimension the array ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to Create array of objects
    ... Postings and the PostingObject[] are 1:1. ... > create an arraylist, then copy that list to an array. ... > dtStartDate, DateTime dtEndDate) ...
    (microsoft.public.dotnet.languages.csharp)
  • Does this constructor require a call to an array "add" method
    ... Should possibly have an "add" method in a PostingObject class in the ... this in the PostingObject Constructor? ... public String EndDate ... John Haigh ...
    (microsoft.public.dotnet.languages.csharp)