[英]Unable to cast object Type Error
无法投放对象类型错误
码
class Person
{
public int Addition(int a, int b)
{
return a + b;
}
}
class Developer : Person
{
public void Addition(int a, int b)
{
int sum = a + b;
Console.WriteLine("Total is {0}{1}" + sum);
}
}
class CHashDeveloper : Developer
{
static void Main(string[] args)
{
Developer objDeveloper =(Developer) new Person(); // Error Occurred here
}
我需要做的事情才能解决此类错误。 }
一个Person
不是Developer
。
您只能将对象转换为该对象实际为的类型。
如果要创建Developer
,则需要编写: new Developer()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.