Can I use a class as an object in C# to create instances of that class?

Posted by Troy on Stack Overflow See other posts from Stack Overflow or by Troy
Published on 2010-03-20T00:18:09Z Indexed on 2010/03/20 0:21 UTC
Read the original article Hit count: 597

Filed under:

I'm writing a fairly uncomplicated program which can "connect" to several different types of data sources including text files and various databases. I've decided to implement each of these connection types as a class inherited from an interface I called iConnection. So, for example, I have TextConnection, MySQLConnection, &c... as classes.

In another static class I've got a dictionary with human-readable names for these connections as keys. For the value of each dictionary entry, I want the class itself. That way, I can do things like:

newConnection = new dict[connectionTypeString]();

Is there a way to do something like this? I'm fairly new to C# so I'd appreciate any help.

© Stack Overflow or respective owner

Related posts about c#