111,126
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 泛型接口
{
public interface Add<T>
{
T add(T x, T y);
}
class math<T> : Add<T>
{
public T add(T x, T y)
{
return x + y;
}
}
class Program
{
static void Main(string[] args)
{
math<int> s = new math<int>();
int z = s.add(4, 7);
Console.WirteLine(z);
Console.Read();
}
}
}
using System;
namespace 泛型接口
{
public interface Add<T>
{
string add(T x, T y);
}
class math<T> : Add<T>
where T: IConvertible
{
public string add(T x, T y)
{
return (x.ToInt32(null) + y.ToInt32(null)).ToString();
}
}
class Program
{
static void Main(string[] args)
{
math<int> s = new math<int>();
int z = int.Parse(s.add(4, 7));
Console.WriteLine(z);
Console.Read();
}
}
}using System;
namespace 泛型接口
{
public interface Add<T>
{
int add(T x, T y);
}
class math<T> : Add<T>
where T: IConvertible
{
public int add(T x, T y)
{
return x.ToInt32(null) + y.ToInt32(null);
}
}
class Program
{
static void Main(string[] args)
{
math<int> s = new math<int>();
int z = s.add(4, 7);
Console.WriteLine(z);
Console.Read();
}
}
}