473,386 Members | 1,736 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,386 software developers and data experts.

C# class declaration

Hello All,

I came across this class declaration and don't really understand the
syntax
public sealed class PdfReport<ReportClass: PdfFormatter where
ReportClass : Root.Reports.Report, new()
{

}

Specifically the PdfReport<ReportClasspart.
Pointers appreciated

thanks in advance
Aug 19 '08 #1
4 2219
On Aug 19, 5:42*pm, hharry <paulquig...@nyc.comwrote:
I came across this class declaration and don't really understand the
syntax
public sealed class PdfReport<ReportClass: PdfFormatter where
ReportClass : Root.Reports.Report, new()
{

}

Specifically the PdfReport<ReportClasspart.
Pointers appreciated
It means that the type is generic. Generics is a big topic - too big
to do justice to in a newsgroup post - but there's plenty written
about it on the web. This MSDN article has several more linking off
it:
http://msdn.microsoft.com/en-us/library/512aeb7t.aspx

Jon
Aug 19 '08 #2
On Aug 19, 12:45*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Aug 19, 5:42*pm, hharry <paulquig...@nyc.comwrote:
I came across this class declaration and don't really understand the
syntax
public sealed class PdfReport<ReportClass: PdfFormatter where
ReportClass : Root.Reports.Report, new()
{
}
Specifically the PdfReport<ReportClasspart.
Pointers appreciated

It means that the type is generic. Generics is a big topic - too big
to do justice to in a newsgroup post - but there's plenty written
about it on the web. This MSDN article has several more linking off
it:http://msdn.microsoft.com/en-us/library/512aeb7t.aspx

Jon
Thanks Jon. I'll read-up on it.
Aug 19 '08 #3
>public sealed class PdfReport<ReportClass: PdfFormatter where
>ReportClass : Root.Reports.Report, new()
>It means that the type is generic.
What is the ", new()" part? I don't recognise that.
Aug 19 '08 #4
Peter Morris <mr*********@SPAMgmail.comwrote:
public sealed class PdfReport<ReportClass: PdfFormatter where
ReportClass : Root.Reports.Report, new()
It means that the type is generic.

What is the ", new()" part? I don't recognise that.
It's part of the generic type constraint - it means that the type
argument has to have a parameterless constructor. Within the class,
they could then do:

ReportClass x = new ReportClass();

You can't specify any parameterised constructors - just the
parameterless one.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Aug 19 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Trevor Lango | last post by:
What is the appropriate syntax for placing a friend function that includes as one of it's parameters a pointer to the class object itself within the template class? I have the following: ...
5
by: Walt Karas | last post by:
Is this code legal under the standard? struct A { int i; struct C { unsigned offset_of_c(void) { return((unsigned) &(((A *) 0)->c)); }
5
by: Xiangliang Meng | last post by:
Hi, all. What are the benefit and the drawback of defining a class embedded inside another class? For example: class List { public:
21
by: anddos | last post by:
i am just wondering what is the friend in a class , ive got a book about c++ but it dosent explain deep enough . anyone care to make a example with a few notes on what the friend can benifit from....
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
3
by: yancheng.cheok | last post by:
hello all, how can i make, a forward declaration class's enum member, being visible by another class? consider the following case, ---------------------------- dog.h...
4
by: zfareed | last post by:
#include <iostream> #include <fstream> using namespace std; template<class ItemType> class SortedList { private:
7
by: Jess | last post by:
Hello, I'd like to declare two classes to be friend classes, I did the following: #include<iostream> using namespace std; class A{
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.