Advertisement

07.17.2008 at 10:14AM PDT, ID: 23574062
[x]
Attachment Details

How to create this List<>?

Asked by brettr in .NET Framework 3.x versions, Microsoft Visual C#.Net, .Net Editors & IDEs

I'd like to create a List<baseType> that can be looped through.  I'll call a method in the loop that can have different signatures.  Is there a way to do this?
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
List<baseType> myList = new List<baseType>();
myList.Add(someChild1);
myList.Add(someChild2);
 
foreach(myClass my in myClassList)
{
foreach(baseType b in myList)
{
  b.DoSomething(common1, common2, my.different1);
  b.DoSomething(common1, common2, my.different2);
  b.DoSomething(common1, common2, my.different3);
}
}
 
//////
abstract class baseType<T>
{
 public abstract void DoSomething(common1, common2, List<T>);
}
 
//////
class someChild1 : baseType<different1>
{
 public override void DoSomething(common1, common2, different1){...}
}
 
class someChild2 : baseType<different2>
{
 public override void DoSomething(common1, common2, different2){...}
}
[+][-]07.17.2008 at 10:57AM PDT, ID: 22028119

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 11:31AM PDT, ID: 22028544

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 03:17AM PDT, ID: 22042053

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.19.2008 at 02:24PM PDT, ID: 22043708

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 02:38PM PDT, ID: 22043749

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET Framework 3.x versions, Microsoft Visual C#.Net, .Net Editors & IDEs
Sign Up Now!
Solution Provided By: Hendo1973
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628