Syntax question

  • Thread starter Thread starter Martin Hart
  • Start date Start date
M

Martin Hart

Hi:

Can some kind person tell me the syntax for declaring and creating an
array of generic List<decimal>'s?

For instance:

List<decimal>[] seriesValues = List<decimal>()[numSeries];

is *not* correct, so how should I go about it?

TIA,
MartinH.
 
Hi:

Can some kind person tell me the syntax for declaring and creating an
array of generic List<decimal>'s?

For instance:

List<decimal>[] seriesValues = List<decimal>()[numSeries];

is *not* correct, so how should I go about it?

TIA,
MartinH.
// Create your array
List<decimal>[] seriesValues = new List<decimal>[numSeries];
// create the elements of the array (not needed if it's
// an array of Value Types like e.g. int)
for (int i = 0; i < numSeries; i) {

seriesValues = new List<decimal>();

}
 
Hi Martin,

Note that you are not creating a List here, only an array. The parentheses
are the problem. Consider the following:

decimal[] decimalValues = new decimal[numSeries];
List[] seriesValues = new List[];

Now, apply that to your array lof List<decimal> :

List<decimal>[] seriesValues = List<decimal>[numSeries];

Remember that a Generic type is only Generic until you use it. One you pass
a type parameter to it, it is no longer Generic, and you should treat it
just like any other type. Treat it as if the type parameter is not there,
but only as if it *is* that type.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Kevin:

Yes, that was the problem.

Thanks very much.

Regards,
MartinH.

Kevin Spencer escribió:
 
Thanks for the ultra quick answer Simon :-)

Regards,
MartinH.

Simon Smith escribió:
Hi:

Can some kind person tell me the syntax for declaring and creating an
array of generic List<decimal>'s?

For instance:

List<decimal>[] seriesValues = List<decimal>()[numSeries];

is *not* correct, so how should I go about it?

TIA,
MartinH.
// Create your array
List<decimal>[] seriesValues = new List<decimal>[numSeries];
// create the elements of the array (not needed if it's
// an array of Value Types like e.g. int)
for (int i = 0; i < numSeries; i) {

seriesValues = new List<decimal>();

}
 
Back
Top