473,398 Members | 2,427 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,398 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 10592
"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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.