728x90
public partial class Program
{
private delegate void AdditionDelegate<T1, T2>(T1 value1, T2 value2);
private static void AddIntDouble(int x, double y)
{
Console.WriteLine($"int {x} + double {y} = {x + y}");
}
private static void AddFloatDouble(float x, double y)
{
Console.WriteLine($"float {x} + double {y} = {x + y}");
}
private static void ActiondelegateInvoke()
{
Action<int, double> intDoubleAddAction = AddIntDouble;
Action<float, double> FloatDoubleAddAction = AddFloatDouble;
intDoubleAddAction(1, 5.4);
FloatDoubleAddAction((float)9.4, 5.4);
}
}
public partial class Program
{
private delegate TResult AddAndConvert<T1, T2, TResult>(T1 digit1, T2 digit2);
private static float AddIntDoubleConvert(int x, double y)
{
float result = (float)(x + y);
Console.WriteLine($"(int) {x} + (double) {y} = (float) {result}");
return result;
}
private static int AddFloatDoubleConvert(float x, double y)
{
int result = (int)(x + y);
Console.WriteLine($"(float) {x} + (double) {y} = (int) {result}");
return result;
}
private static void FuncDelegateInvoke()
{
Func<int, double, float> intDoubleAddConvertToFloatFunc = AddIntDoubleConvert;
Func<float, double, int> floatDoubleAddCOnvertToIntFunc = AddFloatDoubleConvert;
float f = intDoubleAddConvertToFloatFunc(5, 6.2);
int i = floatDoubleAddCOnvertToIntFunc((float)6.8, 6.2);
}
}
public partial class Program
{
static void Main(string[] args)
{
ActiondelegateInvoke();
FuncDelegateInvoke();
}
}
728x90
'c#' 카테고리의 다른 글
[C#] Equals(), == 차이 (0) | 2023.01.16 |
---|---|
System.InvalidCastException(System.Data.DataSetExtensions.dll) (0) | 2023.01.16 |
[C#] Delegate 제네릭 (0) | 2023.01.15 |
[C#] Delegate 멀티캐스트 (0) | 2023.01.14 |
[C#] Delegate3 (0) | 2023.01.14 |