110,533
社区成员
发帖
与我相关
我的任务
分享
class Program
{
static void Main()
{
//从Console接受用户数据
int num1 = int.Parse(Console.ReadLine());
int num2 = int.Parse(Console.ReadLine());
Demo demo = new Demo();
int result = demo.Add(num1,num2);
}
}
public class Demo
{
//Add方法重载
public int Add(int num1,int num2)
{
return num1 + num2;
}
public string Add(string str1,string str2)
{
return str1 + str2;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i = 3, j = 4;
Console.WriteLine(Add<int>(i, j, (x1, x2) => x1 + x2));
string s1 = "Hello", s2 = " World!";
Console.WriteLine(Add<string>(s1, s2, (x1, x2) => x1 + x2));
}
static T Add<T>(T left, T right, Func<T, T, T> add)
{
return add(left, right);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i = 3, j = 4;
Console.WriteLine(Add(i, j));
string s1 = "Hello", s2 = " World!";
Console.WriteLine(Add(s1, s2));
}
static string Add(string left, string right)
{
return left + right;
}
static int Add(int left, int right)
{
return left + right;
}
}
}