不能根据返回值来重载方法是什么意思

liujianliang 2007-12-16 11:58:54
他的意思是否重载的返回类型要求是一致的?
但是我试了一下不同的返回类型,是可以的
using System;
using System.Collections.Generic;
using System.Text;

namespace homework4_1
{
class Program
{
double num;
public void MyMethod(int a,int b)
{
num=Math.Pow(a, b);
Console.WriteLine(num);
}

public int MyMethod(int a, int b,int c)
{

return a * b*c;
}
static void Main(string[] args)
{
Program test = new Program();
test.MyMethod(3,2);
int num = test.MyMethod(2, 2, 2);
Console.WriteLine(num);
}
}
}
...全文
73 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
crossrowman 2007-12-16
  • 打赏
  • 举报
回复
意思就是这样的重载是不对的
public void MyMethod(int a,int b)
{
}
public int MyMethod(int a, int b)
{
}
品铭工作室 2007-12-16
  • 打赏
  • 举报
回复
public void MyMethod(int a,int b)

public int MyMethod(int a, int b)
你写两个这样的重载方法,看可否通过编译,he he
是否可以重载只在于参数的个数和类型,不限制于返回的类型

110,524

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧