using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace csharp_重载
{
class Program
{
static int a(int a1,int a2)
{
return a1-a2;
}
static short a(short b1, short b2)
{
return b1+b2;//无法将int 隐式转换为short 是什么意思 我不是定义b1 b2为short了吗 哪里来的int??
//return (short)(b1+b2);
}
static void Main(string[] args)
{
//double re= Convert.ToDouble(a(15.1,12));
double re=a(15.1,12.2);// 报错说无法double转换int 又是 哪里来的int??
Console.WriteLine(re);
}
}
}错误1 无法将类型“int”隐式转换为“short”。存在一个显式转换(是否缺少强制转换?) 16
错误2 与“csharp_重载.Program.a(int, int)”最匹配的重载方法具有一些无效参数22
错误3 参数“1”: 无法从“double”转换为“int”22
错误4 参数“2”: 无法从“double”转换为“int”22 路过的大侠指点啊!!!
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace csharp_重载
{
class Program
{
static int a(int a1,int a2)
{
return a1-a2;
}
static short a(short b1, short b2)
{
return b1+b2;//无法将int 隐式转换为short 是什么意思 我不是定义b1 b2为short了吗 哪里来的int??
//return (short)(b1+b2);
}
static void Main(string[] args)
{
//double re= Convert.ToDouble(a(15.1,12));
double re=a(15.1,12.2);// 报错说无法double转换int 又是 哪里来的int??
Console.WriteLine(re);
}
}
}错误1 无法将类型“int”隐式转换为“short”。存在一个显式转换(是否缺少强制转换?) 16
错误2 与“csharp_重载.Program.a(int, int)”最匹配的重载方法具有一些无效参数22
错误3 参数“1”: 无法从“double”转换为“int”22
错误4 参数“2”: 无法从“double”转换为“int”22 路过的大侠指点啊!!!
short x = 5, y = 12;
以下赋值语句将产生一个编译错误,原因是赋值运算符右侧的算术表达式在默认情况下的计算结果为 int 类型。short z = x + y; // Error: no conversion from int to short 若要解决此问题,请使用强制转换:short z = ( short )(x + y); // OK: explicit conversion 但是,在目标变量具有相同或更大的存储大小时,使用下列语句是可能的: 复制代码
int m = x + y;
long n = x + y;
不存在从浮点型到 short 的隐式转换。例如,除非使用显式强制转换,否则以下语句将生成一个编译器错误: 复制代码
short x = 3.0; // Error: no implicit conversion from double
short y = (short)3.0; // OK: explicit conversion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace csharp_重载
{
class Program
{
static int a(int a1,int a2)
{
return a1-a2;
}
static float a(float b1,float b2)
{
return b1 + b2;
//return Convert.ToDouble(b1+b2);
}
static void Main(string[] args)
{
//double re= Convert.ToDouble(a(15.1,12));
double re= Convert.ToDouble(a(15.1,12.2));
Console.WriteLine(re);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace csharp_重载
{
class Program
{
static int a(int a1,int a2)
{
return a1-a2;
}
static float a(float b1,float b2)
{
return b1 + b2;
//return Convert.ToDouble(b1+b2);
}
static void Main(string[] args)
{
//double re= Convert.ToDouble(a(15.1,12));
double re= Convert.ToDouble(a(15.1F,12.2F));
Console.WriteLine(re);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace csharp_重载
{
class Program
{
static int a(int a1,int a2)
{
return a1-a2;
}
static short a(short b1, short b2)
{
return b1+b2;//无法将int 隐式转换为short 是什么意思 我不是定义b1 b2为short了吗 哪里来的int??
//return (short)(b1+b2);
}
static void Main(string[] args)
{
//double re= Convert.ToDouble(a(15.1,12));
double re=a(15.1f,12.2f);// 报错说无法double转换int 又是 哪里来的int??
Console.WriteLine(re);
}
}
}