Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created May 24, 2014 00:44
Show Gist options
  • Save Fhernd/131f0acee11e6d7f2a91 to your computer and use it in GitHub Desktop.
Save Fhernd/131f0acee11e6d7f2a91 to your computer and use it in GitHub Desktop.
Uso de los delegados genéricos en C#.
// ===++===
//
// OrtizOL
//
// ===--===
/*============================================================
//
// Clase: DelegadosGenericos.cs
//
// Propósito: Uso de delegados genéricos.
//
============================================================*/
using System;
namespace Articulos.Cap03
{
internal delegate T Calcular<T>(T a, T b);
internal class DelegadosGenericos
{
public static T Sumar<T>(T a, T b)
{
dynamic num1 = a;
dynamic num2 = b;
return num1 + num2;
}
public static void Main()
{
Calcular<double> sumaDoubles = new Calcular<double>(Sumar<double>);
Calcular<int> sumaInts = new Calcular<int>(Sumar<int>);
Console.WriteLine(sumaDoubles(7.3, 9.3).ToString());
Console.WriteLine(sumaDoubles(7, 9).ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment