Content deleted Content added
→List of languages: Added Perl as having "full support" |
→Examples: Added C# |
||
Line 199:
==Examples==
Numerous languages support anonymous functions, or something similar.
===C#===
[[C Sharp (programming language)|C#]] has partial anonymous function support through the use of [[Delegate (.NET)|delegates]].
Somewhat similar to PHP delegates are given a unique name but unlike PHP the name is not required for the delegate to be used.
(The example has been trimmed down to demonstrate the anonymous functionality.)
<source lang="csharp">
delegate int DeletateClass(int x);
DelegateClass d = delegate(int x) {
return x*x;
};
System.Console.WriteLine("{0}^2 = {1}", 10, d(10));
</source>
The C# compiler takes the code block of the anonymous function and creates a static private function whose name is based on the function in which it is declared.
As mentioned above the example is trimmed down to demonstrate the anonymous function instead of using valid C# syntax.
Since anonymous methods are not nameless and can only be declared inside methods of classes then C# does not support full anonymous functionality.
===JavaScript===
|