what function does the 'where' keyword have in this abstract class declaration?

  • Thread starter Thread starter hazz
  • Start date Start date
H

hazz

public abstract class FormShellApplication<TWorkItem, TShell> : WindowsFormsApplication<TWorkItem, TShell>
where TWorkItem : WorkItem, new()
where TShell : Form

thank you,
-hazz
 
public abstract class FormShellApplication said:
WindowsFormsApplication<TWorkItem, TShell>
where TWorkItem : WorkItem, new()
where TShell : Form

The where keyword is used to apply restrictions to the kinds of types that
client code can use for type arguments when it instantiates a class. In the
your example the "TWorkItem : WorkItem, new()" constraint restricts the TWorkItem
generic parameter to inherit from the WorkItem class and have a default,
parameterless constructor. The "where TShell : Form" constraint restricts
the TShell generic parameter to inherit from the Form class.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
It constrains the generic parameters to specific types. TWorkItem, for
example, must derive from the calss WorkItem and provide a parameterless
constructor and TShell must derive from the class Form


public abstract class FormShellApplication<TWorkItem, TShell> :
WindowsFormsApplication<TWorkItem, TShell>
where TWorkItem : WorkItem, new()
where TShell : Form

thank you,
-hazz
 
I see. So this works hand in hand with generics then, if I understand this
correctly now.

Thank you Daniel.
-Greg
 
Thank you Anders.
Since generics allow any object...if that is a correct statement, then the
where statements are a way of specifying that in this case, only certain
objects will work and are allowed.

-hazz
 
Back
Top