Пример #1
0
        public static void Main(string[] args)
        {
            //DelegateRepository delegateRepo = new DelegateRepository();  Why won't it acknowledge my repo???? WHY?!?!?!?!?!


            HelloMethodDelegate del = new HelloMethodDelegate(HelloMethod);

            del("Hello from HelloMethod via HelloMethodDelegate");

            Console.ReadLine();
        }
Пример #2
0
    static void Main()
    {
        // we can call Hello method manually
        Hello("manual hello");

        // need to create an instance of a delegate in order to make it point to a method (Hello)
        // this is where a delegate is similar to a class
        // invoke delegate with a string argument in order to call the Hello method
        HelloMethodDelegate myDelegate = new HelloMethodDelegate(Hello);
        myDelegate("hello from my delegate");
    }
Пример #3
0
        public static int Main(string [] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: client.exe <IP address>");
                return(-1);
            }

            ChannelServices.RegisterChannel(new TcpChannel(), false);
            var obj = (Interface)Activator.GetObject(typeof(RemotingBug.Interface), "tcp://" + args[0] + ":8085/SayHello");

            if (obj == null)
            {
                return(-1);
            }

            var          m1 = new HelloMethodDelegate(obj.HelloMethod);
            var          m2 = new HelloMethodWithRefDelegate(obj.HelloMethodWithRef);
            string       s  = "Hello";
            IAsyncResult tmp;

            // Test 1: direct call
            Console.WriteLine(obj.HelloMethod(s));

            // Test 2: delegate call
            Console.WriteLine(m1(s));

            // Test 3: invoke call
            Console.WriteLine(m1.Invoke(s));

            // Test 4: async call, with ref
            tmp = m2.BeginInvoke(ref s, null, null);
            Console.WriteLine(m2.EndInvoke(ref s, tmp));

            // Test 5: async call, no ref
            tmp = m1.BeginInvoke(s, null, null);
            Console.WriteLine(m1.EndInvoke(tmp));

            return(0);
        }
Пример #4
0
        static void Main(string[] args)
        {
            HelloMethodDelegate del = new HelloMethodDelegate(HelloMethod);

            del("Hello");
        }