在其他班级上选班 [英] Casting a class in another class
本文介绍了在其他班级上选班的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们...
任何人都可以告诉我是否可以在用户定义的类中强制转换Reader类
例如
假设我有具有雇员信息的阅读器对象,并且我想将其强制转换为雇员类对象.有可能吗?
谢谢.
Hi Friends...
Can any tell me is it possible to cast a Reader class in User defined Class
For e.x.
Suppose i have object of reader which have information of employee and i want to cast it in employee class object. Is it possible.
Thanks.
推荐答案
这是可能的,但前提是您的读者是Employee类的后代或实现相同的接口:
1)
It''s possible, but only when your reader is either descendant of Employee class or realizes the same interface:
1)
public class Employee
{
...
}
public class Reader: Employee
{
...
}
2)
2)
interface IEmployee
{
...
}
public class Employee: IEmployee
{
...
}
public class Reader: IEmployee
{
...
}
这篇关于在其他班级上选班的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文