473,320 Members | 1,987 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,320 software developers and data experts.

how to Create array of objects

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


Nov 16 '05 #1
4 8484
Is it true that Postings and the PostingObject[] will not be 1:1? If so,
create an arraylist, then copy that list to an array.
public PostingObject[] GetPostings(string sChannelGuid, DateTime
dtStartDate, DateTime dtEndDate)
{
PostingObject[] oReturnedCol = null;
ArrayList ret = new ArrayList();

//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 > start date and < end date ???
PostingObject post = new PostingObject( dtStartDate, dtEndDate );
ret.Add(post );
}

oReturnedCol = new PostingObject[ret.Count];
return ret.CopyTo(oReturnedCol, 0);
}

If PostingObject[] is 1:1 with Postings then you can dimension the array
after aChannel.Postings and fill the array in the loop:
public PostingObject[] GetPostings(string sChannelGuid, DateTime
dtStartDate, DateTime dtEndDate)
{
PostingObject[] oReturnedCol = null;
ArrayList ret = new ArrayList();

//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);

oReturnedCol = new PostingObject[oPostCol .Count];
for (int i = 0; i < oPostCol.Count; i++)
{
// ??? If > start date and < end date ???
PostingObject post = new PostingObject( dtStartDate, dtEndDate );
oReturnedCol[i] = post;
}

return oReturnedCol;
}

Obviously I don't know if this will compile, but that should give you a few
ideas.

HTH;
Eric Cadwell
http://www.origincontrols.com
Nov 16 '05 #2
Yes, Postings and the PostingObject[] are 1:1.

It does help. I am stuck on the fact that I possibly should have an add
method in the PostingObject class and that my constructors in PostingObject
should call this add method? Does this make sense? My sense is that a
PostingObject needs a Posting, so would I do this in the PostingObject
Constructor?

Thanks for your help.

John
"Eric Cadwell" <ec******@ns.insight.com> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
Is it true that Postings and the PostingObject[] will not be 1:1? If so,
create an arraylist, then copy that list to an array.
public PostingObject[] GetPostings(string sChannelGuid, DateTime
dtStartDate, DateTime dtEndDate)
{
PostingObject[] oReturnedCol = null;
ArrayList ret = new ArrayList();

//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 > start date and < end date ???
PostingObject post = new PostingObject( dtStartDate, dtEndDate );
ret.Add(post );
}

oReturnedCol = new PostingObject[ret.Count];
return ret.CopyTo(oReturnedCol, 0);
}

If PostingObject[] is 1:1 with Postings then you can dimension the array
after aChannel.Postings and fill the array in the loop:
public PostingObject[] GetPostings(string sChannelGuid, DateTime
dtStartDate, DateTime dtEndDate)
{
PostingObject[] oReturnedCol = null;
ArrayList ret = new ArrayList();

//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);

oReturnedCol = new PostingObject[oPostCol .Count];
for (int i = 0; i < oPostCol.Count; i++)
{
// ??? If > start date and < end date ???
PostingObject post = new PostingObject( dtStartDate, dtEndDate );
oReturnedCol[i] = post;
}

return oReturnedCol;
}

Obviously I don't know if this will compile, but that should give you a few ideas.

HTH;
Eric Cadwell
http://www.origincontrols.com

Nov 16 '05 #3
You could pass the Posting or Posting[] into the PostingObject constructor.

Sounds like you need a strongly typed collection. Look at inheriting from
CollectionBase.
You may also want to parameterize your call to get the postings to include
the date range. That might simplify things a bit.

HTH;
Eric Cadwell
http://www.origincontrols.com
Nov 16 '05 #4
You could pass the Posting or Posting[] into the PostingObject constructor.

Sounds like you need a strongly typed collection. Look at inheriting from
CollectionBase.
You may also want to parameterize your call to get the postings to include
the date range. That might simplify things a bit.

HTH;
Eric Cadwell
http://www.origincontrols.com
Nov 16 '05 #5

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

Similar topics

5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
2
by: Raphael Iloh | last post by:
Hi all, I'm having problems comparing array objects. Take a look at this: int array1 = new int{1}; int array2 = new int{1}; Console.Writeln(array1.Equals(array2)); One would expect the above...
10
by: Steve | last post by:
this code: private Array m_arrays = new Array; results in an array of 3 null Array objects. What am I missing?
0
by: antonyliu2002 | last post by:
I am not new to programming, but I am new to VB .NET. I have a multiselect listbox like this: Please select your favorite fruit: Apple Banana Coconut Date
0
by: Raju | last post by:
Hi all i am Rajendran I am working as a asp.net programmer. I am frish to this field so please any of u garify my doubt I Create array of Textbox Dynamically and not passible to retrieve data...
1
by: dragannis | last post by:
Hello, I realy need help about this, I have database that I want to use in my Vb code, and I need to create array from elements of one field from that mdb. Why : I need to do some calculations...
12
by: =?Utf-8?B?RGFuaWVs?= | last post by:
Hi, I have create a class name employee. Next, i would like to create array for the employee class. The code as below: dim eply(5) as employee when i call eply(0).name="Khrish", an error...
3
by: shuvo2k6 | last post by:
How to create OLE Objects at run time, anyone give me the code solution
0
by: davaahuu | last post by:
how to create array with audio files?, Is it possible?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.