1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cannot create/invoke delegate

Discussion in 'C#' started by AhmedHan, Apr 16, 2010.

  1. AhmedHan

    AhmedHan New Member

    Joined:
    Oct 11, 2005
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    TcpClient.cs
    Code:
    namespace TCP_Communication
    {
        class TcpClient
        {
            // ...
            public delegate void OnDataAvailable(char[] data);
            // ...
        }
    }
    Program.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace TCP_Communication
    {
        class Program
        {
            static void Main(string[] args)
            {
                // ...
                Client.OnDataAvailable = DataArrived;
                // ...
            }
            public void DataArrived(char[] newdata)
            {
                // empty for now
            }
        }
    }
    Error:
    Yes, I tried 'TCP_Communication.TcpClient.OnDataAvailable' instead even though it is obviously wrong:

    Program.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace TCP_Communication
    {
        class Program
        {
            static void Main(string[] args)
            {
                // ...
                TCP_Communication.TcpClient.OnDataAvailable = DataArrived;
                // ...
            }
            public void DataArrived(char[] newdata)
            {
                // empty for now
            }
        }
    }
    This time it gives this error message:
    I read the article in MSDN about C# delegates, but still I can't find what I'm missing.

    Please help me guys, how can I fix this code?
     
  2. AhmedHan

    AhmedHan New Member

    Joined:
    Oct 11, 2005
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    I tried writing "public class {};" instead of "class {}", but it didn't do any good.
     

Share This Page