473,246 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 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 1546
> 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
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
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
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
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
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
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
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
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
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
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.