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

Posted on 2007-08-04
Last Modified: 2013-12-17
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
                return this.itemsField;
                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.

Question by:scope_creep

    Author Comment

    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[]


    LVL 18

    Expert Comment

    by:Gary Davis
    The Items property is an array of "object" but you are trying to set it to a single object.

    Gary Davis

    Author Comment


    Ignore this question, I answered it myself.

    LVL 37

    Accepted Solution

    OutboungMessage.Items = new object [] { Alert };



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now