Interface IPerson
{
}
Class A:IPerson
{}
Class B:IPerson()
{}
Class C
{
Object[] obj=new Object[]
{
new A(),
new B()
};
}
How to convert this Object array to strongly typed array?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jan 21, 2014, 8:21 AM
try
IPerson[] obj = new IPerson[] {
new A(),
new B()
};
foreach (IPerson person in obj)
{
//Process the data
}
hope this will help you.
VulpesPosted Jan 21, 2014, 7:40 AM
However, as both classes implement IPerson, you can convert it to an IPerson[] which is more strongly typed than Object[].
Here's the code:
The output is:
A
B
Jaganathan BantheswaranPosted Jan 21, 2014, 7:34 AM
Here is nice example for collection. You could use try this for Array.