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

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

Similar topics

14
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
3
by: Eric | last post by:
I have a string representation of an object. I create an object of that type through reflection. I would like to create a List<> of those objects. I obviously can't do List<myObject.GetType()>...
2
by: Brian Pelton | last post by:
I am not sure how to fix this problem I've stumbled into... I have a list<> of an interface type. I need to pass that list to a method that adds more objects to the list. But, eventually, I...
5
by: PJ | last post by:
I have a class definition : public class PagingList<T> : List<T> { private int pageSize, pageNumber; public PagingList() { pageSize = (this.Count == 0) ? 1 : this.Count;...
3
by: Varangian | last post by:
Hello, there I have a problem with regards to System.Collections.Generic.List<T> I need to pass a class with implements an interface - TestClass : IPerson I put this class in a...
4
by: =?Utf-8?B?TGFycnlS?= | last post by:
I need some help with a multilevel sorting problem with the List<>. I have a List<ItemToSort( see below ) that needs to be sorted in the following manner: Sort by Level1Id ( ok that was the easy...
7
by: Andrew Robinson | last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v> depending on input parameters and options to the method. 1. Is there any way to convert from a dictionary to a list...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
35
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
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, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
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 =...

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.