• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

How to load a type instance into an object array i.e. object[]

How to load a type into an object array.

 I have this.

 public partial class Message
    {

        private object[] itemsField;

        private decimal versionField;

        private bool versionFieldSpecified;

        public Message()
        {
            this.versionField = ((decimal)(1.0m));
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Mess", typeof(Mess))]
        [System.Xml.Serialization.XmlElementAttribute("Heartbeat", typeof(Heartbeat))]
        public object[] Items
        {
            get
            {
                return this.itemsField;
            }
            set
            {
                this.itemsField = value;
            }
        }

   I have the following code.

            Message OutBoundMessage = new Message();
         
            Alert Alert = new Alert();

            OutBoundMessage.Items =  ((Alert) Alert);   -----> This line does not work.

 
How can I load the alert class into the object array.

regards
scope_creep
0
scope_creep
Asked:
scope_creep
  • 2
1 Solution
 
scope_creepAuthor Commented:
Sorry I meant this.

  I have the following code.

            Message OutBoundMessage = new Message();
         
            Mess Mess = new Mess();

            OutBoundMessage.Items =  ((Mess) Mess);   -----> This line does not work.

I get this. Cannot convert type Mess to object[]


thanks.
Bob

0
 
Gary DavisDir Internet SvcsCommented:
The Items property is an array of "object" but you are trying to set it to a single object.

Gary Davis
0
 
scope_creepAuthor Commented:

Ignore this question, I answered it myself.

Thanks.
0
 
gregoryyoungCommented:
OutboungMessage.Items = new object [] { Alert };


Cheers,

Greg
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now