Операции в над обобщенными типами - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cs_test_app_1 {
class Program {
static void Main(string[] args) {
Console.WriteLine(sum<double>(25.5, 3.2));
Console.Read();
}
static T sum<T>(T x, T to) {
return x + to;
}
}
}Решение задачи: «Операции в над обобщенными типами»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Test t = Sum<Test>(new Test(), new Test());
}
static T Sum<T>(Test t1, Test t2)
{
dynamic dt1 = t1, dt2 = t2;
return dt1 + dt2;
}
}
class Test
{
}
}