Αποτελέσματα Αναζήτησης
14 Νοε 2013 · The only way to create/use a delegate was to define your own new delegate type (or find/guess some suitable one somewhere deep in the system's namespaces). Keep in mind that every new delegate-type is a new class.
5 Ιαν 2022 · Learn how delegates, which define a type that specifies a particular method signature, can be called directly or passed to another method and called.
31 Ιουλ 2023 · Unlike C function pointers, delegates are object-oriented, type safe, and secure. The type of a delegate is defined by the name of the delegate. The following example declares a delegate named Callback that can encapsulate a method that takes a string as an argument and returns void:
29 Σεπ 2022 · Learn how to declare, instantiate, and use a delegate. See examples that cover C# 1.0, 2.0, and 3.0 and later.
15 Σεπ 2011 · Declaring a delegate inside a method would be like declaring a class inside a method because the compiler rewrites the delegate declaration onto a class declaration. This is why you can't do this while it's perfectly valid do assign to a delegate type.
Below we provide two equivalent code of C# and Java. The C# one will be. public delegate int DelegateMultiply(int a, int b); public static void Main(string[] args) DelegateMultiply del = Program.Multiply; Console.WriteLine(del(3, 8)); public static int Multiply(int a, int b) return a * b;
7 Νοε 2021 · In this article, we are going to talk more about delegates in C#. A delegate is a reference to a method. We can use a delegate object to pass it to the code in which we want to call a referenced method, without knowing at compile time which method will be invoked.