Just an interesting note:
While it is not possible conceptually, syntactically , it is really possible to create an instance of an interface under certain circumstances.
.NET has something called CoClassAttribute that tells the compiler to interpret the marked interface as a specific type. Using this attribute will make the following code completely correct and will not display a compile-time error (note that this is not an array, as in the original message):
var x = new IDynamicCode<string>();
A typical declaration of such an attribute would look like this:
[ComImport] [Guid("68ADA920-3B74-4978-AD6D-29F12A74E3DB")] [CoClass(typeof(ConcreteDynamicCode<>))] public interface IDynamicCode<out TCodeOut> { object DynamicClassInstance { get; set; } TCodeOut Execute(string value = ""); }
Should this attribute ever be used, and if, then where? The answer is "mostly never"! However, there are several scenarios specific to COM interoperability where this will be a useful feature.
You can read more about the topic at the following links:
Jaanus varus
source share