generic list question

  • Thread starter Thread starter WebBuilder451
  • Start date Start date
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
 
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...
 
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
 
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...?
 
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
 
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
}
}
 
Back
Top