0

I would like to know how to pass object array (object[]) between classes with the code bellow, which now sends string only:

public delegate void MessageDelegate(Object sender, MessageEventArgs e);

  public class MessageEventArgs : EventArgs
  {
    public string Message;
    public MessageEventArgs(string msg)
    {
      this.Message = msg;
    }
  }
  public interface IController
  {
    event MessageDelegate ControllerEvent;
    void InvokeControllerEvent(string msg);
  }
  public class Controller : IController
  {
    public event MessageDelegate ControllerEvent;

    public void InvokeControllerEvent(string msg)
    {
      this.OnControllerEvent(new MessageEventArgs(msg));
    }

    protected virtual void OnControllerEvent(MessageEventArgs mea)
    {
      if (this.ControllerEvent != null)
      {
        this.ControllerEvent.Invoke(this, mea);
      }
    }
  }

Edited by Mitja Bonca: n/a

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by nick.crane
0

I would like to know how to pass object array (object[]) between classes with the code bellow, which now sends string only:

static void Sample(object[] ar)
        {
            if(ar is string[])
                Console.WriteLine( ((string[])ar)[0]);
        }
        static void Sample1(Array ar)
        {
            if (ar is string[])
                Console.WriteLine(((string[])ar)[0]);
        }
        static void Main(string[] args)
        {
            string[] ar = { "AA", "BB" };
            Sample(ar);
            Sample1(ar);
        }
0

As long as it is within you own app and not a remote app or other process you can just add an object[] as an additional parameter to your MessageEventArgs .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.