Monday, March 2, 2015

How to cast all child elements in an unlimited hierachical data ?

The question is what is the type of subjects?


is it an array or a list, or something else


you may use 'as' to cast back to the type it really is.


for example



Subject[] subjects=theObject.Subjects as Subject[]



You need to have the knowledge what type the original subjects is and what data you stored there before you can convert it to ur own class by a constructor



class MySubject
{
public MySubject(OtherSubject subject)
{
this.Title=subject.Title;
this.Code=subject.Id;
}
}


No comments:

Post a Comment