Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Defining Multiple Types for a Generic Class

You can't define every class using just one datatype. Fortunately, generic classes also accommodate multiple datatypes. All you need to do is separate datatypes with a comma, as shown here:

Public Class MyGenericCollection(Of ItemType1, ItemType2, ItemType3)

This declaration accepts three datatypes (no more, no less) as inputs. In this case, the code doesn't place any constraints on the datatypes, but you can easily add constraints as needed. In fact, you can mix-and-match datatypes with and without constraints in the same declaration and the datatypes that do have constraints need not have the same constraint type. You could include one datatype that uses a specific class and another that relies on an interface.

  • + Share This
  • 🔖 Save To Your Account