次の方法で共有


Some differences between com.ms.lang.Delegate and System.Delegate type in J#

Firstly, instance “invoke” function has different case letters in them:

com.ms.lang.Delegate à invoke

System.Delegate à Invoke

Also, the static functions combine and Remove have different case letters:

com.ms.lang.Delegate à combine

com.ms.lang.Delegate à remove

System.Delegate àCombine

System.Delegate àRemove

Moreover, delegates of com.ms.lang.Delegate type are binded at runtime, while System.Delegates are binded at compile time (until we are not using

System.Delegate.CreateDelegate calls directly).

Hence, the following code snippet compiles fine but throws runtime exception for com.ms.lang.types saying :

java.lang.IllegalArgumentException: Error binding to target method

as there is no function named : “lower” here.

delegate void check(int a, int b);

public class test {

    public void greater( int a, int b ) {

        if (a > b)

         System.out.println("Greater");

        else

            System.out.println("Small");

    }

    public static void main(String args[])

    {

        test t = new test();

        check ch = new check(t, "lower");

        ch.invoke(21, 20);

    }

}

   

While the following code snippet gives the compiler error saying :

error VJS1223: Cannot find method 'lower(int, int)'

 

/**@delegate*/

delegate void check(int a, int b);

public class test

{

    public void greater(int a, int b)

    {

        if (a > b)

            System.out.println("Greater");

        else

            System.out.println("Small");

    }

    public static void main(String args[])

    {

        test t = new test();

        check ch = new check(t, "lower");

        ch.Invoke(21, 20);

    }

}

Comments

  • Anonymous
    November 27, 2005
    t
  • Anonymous
    November 27, 2005
    club de fans sara de lucas
  • Anonymous
    March 17, 2006
    While I was trying to write a blog around the topic of Delegates in J#, I found that a few blogs have...
  • Anonymous
    May 31, 2009
    PingBack from http://outdoorceilingfansite.info/story.php?id=2095