469,267 Members | 1,050 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

how to set default values in instantiating a generic List<>



I have the following code
public enum pdfFlags
{
PFD_DRAW_TO_WINDOW,
PFD_DRAW_TO_BITMAP,
PFD_SUPPORT_GDI,
PFD_SUPPORT_OPENGL,
PFD_GENERIC_ACCELERATED, PFD_GENERIC_FORMAT,
PFD_NEED_PALETTE, PFD_NEED_SYSTEM_PALETTE,
PFD_DOUBLEBUFFER, PFD_STEREO,
PFD_SWAP_LAYER_BUFFERS
};

public List<pdfFlagsdwFlags = new List<pdfFlags>();

is there a way in this decleration line to set the list with default
values. I cant seem to find a way. I think i have a good reason for
wanting to do it here.

for example it want it to always default to a list of

pdfFlags. PFD_DRAW_TO_WINDOW
pdfFlags. PFD_DRAW_TO_BITMAP
pdfFlags. PFD_SUPPORT_OPENGL
thanks for any help

Peted

Sep 21 '07 #1
4 10321
"Peted" wrote in message news:km********************************@4ax.com...
public List<pdfFlagsdwFlags = new List<pdfFlags>();

is there a way in this decleration line to set the list with default
values.
[...]
for example it want it to always default to a list of

pdfFlags.PFD_DRAW_TO_WINDOW
pdfFlags.PFD_DRAW_TO_BITMAP
pdfFlags.PFD_SUPPORT_OPENGL
In C# version 3.0 you can do:

public List<pdfFlagsdwFlags = new List<pdfFlags{
pdfFlags.PFD_DRAW_TO_WINDOW, pdfFlags.PFD_DRAW_TO_BITMAP,
pdfFlags.PFD_SUPPORT_OPENGL };

but, alas, this is not available in earlier versions. If you are using C#
v 2.0, you are stuck with

public List<pdfFlagsdwFlags = new List<pdfFlags>();
dwFlags.Add(pdfFlags.PFD_DRAW_TO_WINDOW);
dwFlags.Add(pdfFlags.PFD_DRAW_TO_BITMAP);
dwFlags.Add(pdfFlags.PFD_SUPPORT_OPENGL);

Sep 21 '07 #2
Hi,

"Marc Gravell" <ma**********@gmail.comwrote in message
news:Os**************@TK2MSFTNGP06.phx.gbl...
From this, and your earlier post, I'm pretty sure you are making this hard
on yourself... why not just treat this as a [Flags] enum and "or" them
together? Given your previous comments about converting to an int, it
seems clear that this is actually bitwise data...

Maybe I'm missing something...
I think the same, it's better to use a Flag enum.
As a matter of fact it struck me as weird having a list of enum.
Sep 21 '07 #3
use this
public List<pdfFlagsdwFlags = new List<pdfFlags>();
dwFlags.Add(pdfFlags.PFD_DRAW_TO_WINDOW);
dwFlags.Add(pdfFlags.PFD_DRAW_TO_BITMAP);
dwFlags.Add(pdfFlags.PFD_SUPPORT_OPENGL);

otherwise make derived class from List<>
and initailize with ur default parameters.

"Alberto Poblacion" wrote:
"Peted" wrote in message news:km********************************@4ax.com...
public List<pdfFlagsdwFlags = new List<pdfFlags>();

is there a way in this decleration line to set the list with default
values.
[...]
for example it want it to always default to a list of

pdfFlags.PFD_DRAW_TO_WINDOW
pdfFlags.PFD_DRAW_TO_BITMAP
pdfFlags.PFD_SUPPORT_OPENGL

In C# version 3.0 you can do:

public List<pdfFlagsdwFlags = new List<pdfFlags{
pdfFlags.PFD_DRAW_TO_WINDOW, pdfFlags.PFD_DRAW_TO_BITMAP,
pdfFlags.PFD_SUPPORT_OPENGL };

but, alas, this is not available in earlier versions. If you are using C#
v 2.0, you are stuck with

public List<pdfFlagsdwFlags = new List<pdfFlags>();
dwFlags.Add(pdfFlags.PFD_DRAW_TO_WINDOW);
dwFlags.Add(pdfFlags.PFD_DRAW_TO_BITMAP);
dwFlags.Add(pdfFlags.PFD_SUPPORT_OPENGL);

Sep 22 '07 #4
Hi use first u need to define ur own class deriverd from List<>
like this
public enum pdfFlags
{
PFD_DRAW_TO_WINDOW,
PFD_DRAW_TO_BITMAP,
PFD_SUPPORT_GDI,
PFD_SUPPORT_OPENGL,
PFD_GENERIC_ACCELERATED, PFD_GENERIC_FORMAT,
PFD_NEED_PALETTE, PFD_NEED_SYSTEM_PALETTE,
PFD_DOUBLEBUFFER, PFD_STEREO,
PFD_SWAP_LAYER_BUFFERS
}

class defaultpdf<T: List<T>
{
public defaultpdf(T t1,T t2,T t3)
{
this.Add(t1);
this.Add(t2);
this.Add(t3);
}
}
now use ur class as
defaultpdf<pdfFlagspdf = new
defaultpdf<pdfFlags>(pdfFlags.PFD_DRAW_TO_BITMAP,p dfFlags.PFD_DRAW_TO_WINDOW,pdfFlags.PFD_SUPPORT_OP ENGL);
by default it will initialize ant varaile with 3 count and given by ur
values in constructer.
hope it wiill help u

"Peted" wrote:
>

I have the following code
public enum pdfFlags
{
PFD_DRAW_TO_WINDOW,
PFD_DRAW_TO_BITMAP,
PFD_SUPPORT_GDI,
PFD_SUPPORT_OPENGL,
PFD_GENERIC_ACCELERATED, PFD_GENERIC_FORMAT,
PFD_NEED_PALETTE, PFD_NEED_SYSTEM_PALETTE,
PFD_DOUBLEBUFFER, PFD_STEREO,
PFD_SWAP_LAYER_BUFFERS
};

public List<pdfFlagsdwFlags = new List<pdfFlags>();

is there a way in this decleration line to set the list with default
values. I cant seem to find a way. I think i have a good reason for
wanting to do it here.

for example it want it to always default to a list of

pdfFlags. PFD_DRAW_TO_WINDOW
pdfFlags. PFD_DRAW_TO_BITMAP
pdfFlags. PFD_SUPPORT_OPENGL
thanks for any help

Peted

Sep 22 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Dave | last post: by
3 posts views Thread by Eric | last post: by
2 posts views Thread by Brian Pelton | last post: by
5 posts views Thread by PJ | last post: by
4 posts views Thread by =?Utf-8?B?TGFycnlS?= | last post: by
7 posts views Thread by Andrew Robinson | last post: by
35 posts views Thread by Lee Crabtree | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.