Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Function-prototype/C-sharp/function-prototype-1.cs
Normal file
12
Task/Function-prototype/C-sharp/function-prototype-1.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
abstract class Printer
|
||||
{
|
||||
public abstract void Print();
|
||||
}
|
||||
|
||||
class PrinterImpl : Printer
|
||||
{
|
||||
public override void Print() {
|
||||
Console.WriteLine("Hello world!");
|
||||
}
|
||||
}
|
||||
22
Task/Function-prototype/C-sharp/function-prototype-2.cs
Normal file
22
Task/Function-prototype/C-sharp/function-prototype-2.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
public delegate int IntFunction(int a, int b);
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static int Add(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
public static int Multiply(int x, int y) {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
public static void Main() {
|
||||
IntFunction func = Add;
|
||||
Console.WriteLine(func(2, 3)); //prints 5
|
||||
func = Multiply;
|
||||
Console.WriteLine(func(2, 3)); //prints 6
|
||||
func += Add;
|
||||
Console.WriteLine(func(2, 3)); //prints 5. Both functions are called, but only the last result is kept.
|
||||
}
|
||||
}
|
||||
20
Task/Function-prototype/C-sharp/function-prototype-3.cs
Normal file
20
Task/Function-prototype/C-sharp/function-prototype-3.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
//file1.cs
|
||||
public partial class Program
|
||||
{
|
||||
partial void Print();
|
||||
}
|
||||
|
||||
//file2.cs
|
||||
using System;
|
||||
|
||||
public partial class Program
|
||||
{
|
||||
partial void Print() {
|
||||
Console.WriteLine("Hello world!");
|
||||
}
|
||||
|
||||
static void Main() {
|
||||
Program p = new Program();
|
||||
p.Print(); //If the implementation above is not written, the compiler will remove this line.
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue