Link to home
Start Free TrialLog in
Avatar of scope_creep
scope_creep

asked on

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
Avatar of scope_creep
scope_creep

ASKER

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

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

Gary Davis

Ignore this question, I answered it myself.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial