possible small bug

B

Bram

Hi,

While staying very humble, I might have found a (rather small) bug in the
framework (in one day).
I'm using an older version of Visual C#.NET (7.0.9466) with Framework 1.0
(1.0.3705).
Things might have been fixed. So people with the latest version know what
to do.

Just declare a jagged array like this:

int a[][,] = new int[5][,]; a single-dimensional array of two-dimensional
arrays of ints.

Now get the type of 'a' and get its full name:

a.GetType().FullName

It will return "Int32[,][]"
That is, a 2-dim array of 1-dim array of ints, clearly not the same.
Is this a (small) error if it hasn't been fixed yet, or am I missing
something ?

Greetings,

Bram.
 
J

Jon Skeet [C# MVP]

Bram said:
While staying very humble, I might have found a (rather small) bug in the
framework (in one day).
I'm using an older version of Visual C#.NET (7.0.9466) with Framework 1.0
(1.0.3705).
Things might have been fixed. So people with the latest version know what
to do.

Just declare a jagged array like this:

int a[][,] = new int[5][,]; a single-dimensional array of two-dimensional
arrays of ints.

Now get the type of 'a' and get its full name:

a.GetType().FullName

It will return "Int32[,][]"
That is, a 2-dim array of 1-dim array of ints, clearly not the same.
Is this a (small) error if it hasn't been fixed yet, or am I missing
something ?

I think it's just that the type system (and CIL) does things in a
different order to C#. If you think of the result of GetType().FullName
to be:

(Int32[,])[]

then that's *exactly* correct - an array of (Int32[,]).

It's just that C# expresses that as int[][,] instead.
 
B

Bram

Hadn't thought of it that way.
It even makes more sense.
C# does it its way, because people tend to do things left to right.
Compilers think more in terms of grammars and regular expressions.

Thanks,

Bram.

Jon Skeet said:
Bram said:
While staying very humble, I might have found a (rather small) bug in the
framework (in one day).
I'm using an older version of Visual C#.NET (7.0.9466) with Framework 1.0
(1.0.3705).
Things might have been fixed. So people with the latest version know what
to do.

Just declare a jagged array like this:

int a[][,] = new int[5][,]; a single-dimensional array of two-dimensional
arrays of ints.

Now get the type of 'a' and get its full name:

a.GetType().FullName

It will return "Int32[,][]"
That is, a 2-dim array of 1-dim array of ints, clearly not the same.
Is this a (small) error if it hasn't been fixed yet, or am I missing
something ?

I think it's just that the type system (and CIL) does things in a
different order to C#. If you think of the result of GetType().FullName
to be:

(Int32[,])[]

then that's *exactly* correct - an array of (Int32[,]).

It's just that C# expresses that as int[][,] instead.
 

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

Top