generic list question

W

WebBuilder451

I'm working n a helper class for pages and i thought this would handy, but
i'm not sure if it's possible. It would need to take the args as a dynamic
variable list.

fn(gv1,gv2,gv3,...gvN);
private void fn (List<GridView> gvl)
{
.....
loop or do what ever you need to using the list
.....
}

it's a thought. Any ideas?
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
M

Mark Rae [MVP]

It would need to take the args as a dynamic variable list.

Use a generic...

I do this all the time. E.g. in my DAL, there are several functions which
accept a List<SqlParameter> as an argument so that it doesn't matter how
many SqlParameter objects are passed...
 
W

WebBuilder451

Mark Thanks,
List<GridView> gvl = new List<GridView>();
gvl.Add(gvPhone);
gvl.Add(gvAddr);
gvl.Add(gvEmail);
fn(gvl);
// **************************
public void fn(List<GridView> gvl)
{
foreach (GridView gv in gvl)
{
gv.EditIndex = -1;
}
}
does work. I guess i was hoping to do it in a way that i could give it a
variable length number of parameters in the function.
so that calling fn(gv1,gv2,gv2, ...,gvN) would be possible with out creating
a generic list and then adding the gridviews to it.

Is it?

is it?

In
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
M

Mark Rae [MVP]

List<GridView> gvl = new List<GridView>();
gvl.Add(gvPhone);
gvl.Add(gvAddr);
gvl.Add(gvEmail);
fn(gvl);
// **************************
public void fn(List<GridView> gvl)
{
foreach (GridView gv in gvl)
{
gv.EditIndex = -1;
}
}
does work. I guess i was hoping to do it in a way that i could give it a
variable length number of parameters in the function.
so that calling fn(gv1,gv2,gv2, ...,gvN) would be possible with out
creating
a generic list and then adding the gridviews to it.

Is it?

Maybe I'm not really understanding what you're actually trying to achieve...

Do you, or do you not, want to pass a variable number of GridView parameters
to a function?

Assuming you do, what is the problem with creating a List<GridView> generic
and then passing that to the function?

Seems simple enough - what's the problem...?
 
W

WebBuilder451

I'm thinking of ways to minimize code for UI developers. It would be nice to
just pass the names of the grids or form views. for me it's no problem, but
i'm trying to make things easy for UI people, so they are not tempted to
create a milllion function to change row state on a hadful of gridviews.


--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
K

Kelly Herald

Why not use the params keyword? This way you don't have to create a
separate list first then pass the list in. Be sure to read up on the params
keyword in the MSDN help for more info.

private void fn(params GridView[] gvl)
{
for (int i = 0; i < gvl.Length; i++)
{
// Do whatever for each GridView
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top