从父类中赋值。简单的
怎么做类似的事情:
Class Car: string Name, int year
Class SUV:Car;
SUV bmw=ToCar(car);
类似的事情?
public object ToObject(Type type, Car car)
{
// here i just wanna take string and int pool
}
我做了类似的事情:
List<Car> cars=new List<Car>
SUV suv=new SUV();
cars.Add(suv).
接下来我想要:
SUV suv=(Suv)cars[0];
但我收到一个错误,表明此转换是错误的。 :/
我只想恢复 SUV。
How do something like that:
Class Car: string Name, int year
Class SUV:Car;
SUV bmw=ToCar(car);
Something like that ??
public object ToObject(Type type, Car car)
{
// here i just wanna take string and int pool
}
I did something like:
List<Car> cars=new List<Car>
SUV suv=new SUV();
cars.Add(suv).
And next I want:
SUV suv=(Suv)cars[0];
But I get an error that this casting is wrong. :/
I want to just recover the SUV.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您已经有了基本的想法,您的示例中存在一些命名错误,我假设这些错误只是拼写错误,而不是实际代码的样子...这样的东西工作正常,这就是您的样子正在达到:
It looks like you've got the basic idea, there were some naming errors in your example that I'm assuming were just typos and not what the actual code looks like...something like this works fine which is what it looks like you are getting at: