473,513 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1559
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
2748
by: Steven T. Hatton | last post by:
If a header is not necessarily a source file, and the sequences delimited by < and > in header names aren't necessarily valid source file names, what exactly is a header? -- p->m == (*p).m == p.m...
12
3273
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
1
1465
by: slugster | last post by:
Hi, i originally posted this via another portal, but after giving it time to propagate it still hasn't shown up. My apologies for the multiposting. This might be a very simple question, but i...
24
3311
by: ypjofficial | last post by:
Hello all, I have written a class with many private data members.and i am putting it in a separate dll file. Now when i link that file while writing my main program module,natuarally i have to...
16
3178
by: Bob Hairgrove | last post by:
Consider the classic clone() function: class A { public: virtual ~A() {} virtual A* clone() const = 0; }; class B : public A { public:
4
6091
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
4
6673
by: grizggg | last post by:
I have searched and not found an answer to this question. I ran upon the following statement in a *.cpp file in a member function: static const char * const pacz_HTMLContentTypeHeader =...
7
4251
by: mosfet | last post by:
HI, when trying to compile an embedded version of STL called ustl on win32 platform I get the following error : /// Returns the minimum of \p a and \p b template <typename T1, typename T2>...
3
1978
by: Hongyu | last post by:
Hi, I am a newbie in C++. I saw a code like the below and don't understand it. class A { public: A();
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.