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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jan 21, 2014, 2:34 AM EST
Here is nice example for collection. You could use try this for Array.
VulpesRank #55 · 29.2K reputationPosted Jan 21, 2014, 2:40 AM EST
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
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 21, 2014, 3:21 AM EST
try
IPerson[] obj = new IPerson[] {
new A(),
new B()
};
foreach (IPerson person in obj)
{
//Process the data
}
hope this will help you.