Skip to content

Commit ad51f33

Browse files
committed
Adds source code to the project
1 parent ac2d267 commit ad51f33

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

src/AnonymousMethods/Program.cs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
3+
namespace Samples.AnonymousMethods
4+
{
5+
class MainClass
6+
{
7+
delegate double GetTemp(double d);
8+
public static void Main(string[] args)
9+
{
10+
int x = 44;
11+
Console.WriteLine("{0} Fahrenheit = {1:0.00} Celsius", x, ApplyF(x, delegate (double fahrenheit)
12+
{
13+
return (fahrenheit - 32) * (5 / 9D);
14+
}));
15+
Console.WriteLine("{0} Fahrenheit = {1:0.00} Kelvin", x, ApplyF(x, delegate (double fahrenheit)
16+
{
17+
return fahrenheit + 460;
18+
}));
19+
Console.Read();
20+
}
21+
22+
static double ApplyF(double d, GetTemp f)
23+
{
24+
return f(d);
25+
}
26+
27+
}
28+
}

src/Delegates/Program.cs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
namespace Samples.Delegates
4+
{
5+
class MainClass
6+
{
7+
//definimos al objeto que guardara las referencias a los metódos
8+
delegate double GetTemp(double d);
9+
public static void Main(string[] args)
10+
{
11+
int x = 44;
12+
Console.WriteLine("{0} Fahrenheit = {1:0.00} Celsius", x, ApplyF(x, Temp.GetCelsius));
13+
Console.WriteLine("{0} Fahrenheit = {1:0.00} Kelvin", x, ApplyF(x, Temp.GetKelvin));
14+
Console.Read();
15+
}
16+
17+
//el metódo que aplicará el metódo que es su segundo argumento
18+
static double ApplyF(double d, GetTemp f)
19+
{
20+
return f(d);
21+
}
22+
}
23+
}

src/Delegates/Temp.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
namespace Samples.Delegates
3+
{
4+
public class Temp
5+
{
6+
//la implementación de cada metódo
7+
public static double GetCelsius(double fahrenheit)
8+
{
9+
return (fahrenheit - 32) * (5 / 9D);
10+
}
11+
12+
public static double GetKelvin(double fahrenheit)
13+
{
14+
return fahrenheit + 460;
15+
}
16+
}
17+
}

src/LambdaExp/Program.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
namespace Samples.LambdaExpression
4+
{
5+
class MainClass
6+
{
7+
delegate double GetTemp(double d);
8+
public static void Main(string[] args)
9+
{
10+
int x = 44;
11+
Console.WriteLine("{0} Fahrenheit = {1:0.00} Celsius", x, ApplyF(x, (fahrenheit) => ((fahrenheit - 32) * (5 / 9D))));
12+
Console.WriteLine("{0} Fahrenheit = {1:0.00} Kelvin", x, ApplyF(x, (fahrenheit) => (fahrenheit + 460)));
13+
Console.Read();
14+
}
15+
16+
static double ApplyF(double d, GetTemp f)
17+
{
18+
return f(d);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)