471,337 Members | 860 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

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

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

thank you,
-hazz
Nov 27 '05 #1
4 1482
> public abstract class FormShellApplication<TWorkItem, TShell> :
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/
Nov 27 '05 #2
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
"hazz" <hazz@sonic_net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
public abstract class FormShellApplication<TWorkItem, TShell> :
WindowsFormsApplication<TWorkItem, TShell>
where TWorkItem : WorkItem, new()
where TShell : Form

thank you,
-hazz
Nov 27 '05 #3
I see. So this works hand in hand with generics then, if I understand this
correctly now.

Thank you Daniel.
-Greg

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:eh*************@TK2MSFTNGP11.phx.gbl...
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
"hazz" <hazz@sonic_net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
public abstract class FormShellApplication<TWorkItem, TShell> :
WindowsFormsApplication<TWorkItem, TShell>
where TWorkItem : WorkItem, new()
where TShell : Form

thank you,
-hazz

Nov 27 '05 #4
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

"Anders Norås" <an**********@objectware.no> wrote in message
news:66*************************@news.microsoft.co m...
public abstract class FormShellApplication<TWorkItem, TShell> :
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/

Nov 27 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

31 posts views Thread by Steven T. Hatton | last post: by
12 posts views Thread by Steven T. Hatton | last post: by
24 posts views Thread by ypjofficial | last post: by
16 posts views Thread by Bob Hairgrove | last post: by
4 posts views Thread by grizggg | last post: by
7 posts views Thread by mosfet | last post: by
3 posts views Thread by Hongyu | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.