【发布时间】:2011-04-28 16:33:00
【问题描述】:
我有:
public class Element : XmlElement
{
// there is constructor, not important
public string ElementSomething {get;set;}
}
public class Cat: Element {
// there is constructor, not important
public string CatSomething {get;set;}
}
现在是一个史诗般的问题:
public void SomeMethod()
{
XmlElement xmlelem = new XmlElement (/*some params, not important */);
Element elem = new Element (/*some params, not important*/);
elem.ElementSomething = "Element";
Cat catelem = new Cat(/*some params, not important*/);
catelem .CatSomething = "Cat";
}
如何将elem 转换为Cat 并返回?
Cat newcat = elem as Cat;
不工作。
【问题讨论】: