Skip to content

Why not?

Dave

Asked Apr 16, 2007, 12:43 PM EDT2 answers
Share
LinkedInX
Bit of newbie question here but why can't i do this:

List<ConfigurationFile> INIfilelist = new List<INIFile>();

When i can clearly do this:

ConfigurationFile INI= new INIFile();

INIFile inherits the abstract ConfigurationFile

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    you can't do this with a template.  Templates can only be constructed (as far as I know) with there own type.  You are welcome to put an INIFile inside the collection once you construct it (since it inherits from it), but you need to construct it with the base type.
    0
  • 0
    I think I understand what you're tyring to do. You probably can accomplish it by either: List<\ConfigurationFile> INIfilelist = new List<\ConfigurationFile>(); This may not be do-able with abstract classes, but then you could also do: List<\INIFile> INIfilelist = new List<\INIFile>(); Unless you have a good reason for using the abstract class to form the list, such as needing to put more than one type of class in the list that inherits from ConfigurationFile, you should instead just make a list of INIFile objects (as shown just above this paragraph). Hope that helps. (Sorry about the backslashes... the List types would dissapear without them. They are NOT part of the code)
    0