467,879 Members | 1,349 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

C# Generics: Why int[] doesn't implement IList<int>?

Hello

I was just got VS 2005 preview, and was trying generics.

I tried the following code

int[] intArray = new int[100];
IList<int> intList = (IList<int>) intArray;

it didn't compile, also the following didn't compile

IEnumerable<int> intEnumerable = (IEnumerable<int>)intArray;

IMHO it makes perfect sense that int[] should implement IList<int>,
IEnumerable<int>, etc, since it implements the non-generic IList, and
IEnumerable.

Best regards,
Sherif
Nov 16 '05 #1
  • viewed: 2278
Share:
13 Replies
Please, post whidbey questions to the private whidbey NG, This NG is for
released products.

Willy.

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
Hello

I was just got VS 2005 preview, and was trying generics.

I tried the following code

int[] intArray = new int[100];
IList<int> intList = (IList<int>) intArray;

it didn't compile, also the following didn't compile

IEnumerable<int> intEnumerable = (IEnumerable<int>)intArray;

IMHO it makes perfect sense that int[] should implement IList<int>,
IEnumerable<int>, etc, since it implements the non-generic IList, and
IEnumerable.

Best regards,
Sherif

Nov 16 '05 #2
Please, post whidbey questions to the private whidbey NG, This NG is for
released products.

Willy.

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
Hello

I was just got VS 2005 preview, and was trying generics.

I tried the following code

int[] intArray = new int[100];
IList<int> intList = (IList<int>) intArray;

it didn't compile, also the following didn't compile

IEnumerable<int> intEnumerable = (IEnumerable<int>)intArray;

IMHO it makes perfect sense that int[] should implement IList<int>,
IEnumerable<int>, etc, since it implements the non-generic IList, and
IEnumerable.

Best regards,
Sherif

Nov 16 '05 #3
Sherif,

Given that System.Array implements IList and IEnumerable, the
specialized versions should definitely be supported.

I'll file a bug. Thanks for finding it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
Hello

I was just got VS 2005 preview, and was trying generics.

I tried the following code

int[] intArray = new int[100];
IList<int> intList = (IList<int>) intArray;

it didn't compile, also the following didn't compile

IEnumerable<int> intEnumerable = (IEnumerable<int>)intArray;

IMHO it makes perfect sense that int[] should implement IList<int>,
IEnumerable<int>, etc, since it implements the non-generic IList, and
IEnumerable.

Best regards,
Sherif

Nov 16 '05 #4
Sherif,

Given that System.Array implements IList and IEnumerable, the
specialized versions should definitely be supported.

I'll file a bug. Thanks for finding it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
Hello

I was just got VS 2005 preview, and was trying generics.

I tried the following code

int[] intArray = new int[100];
IList<int> intList = (IList<int>) intArray;

it didn't compile, also the following didn't compile

IEnumerable<int> intEnumerable = (IEnumerable<int>)intArray;

IMHO it makes perfect sense that int[] should implement IList<int>,
IEnumerable<int>, etc, since it implements the non-generic IList, and
IEnumerable.

Best regards,
Sherif

Nov 16 '05 #5
Nicholas Paldino [.NET/C# MVP] wrote:
Sherif,

Given that System.Array implements IList and IEnumerable, the
specialized versions should definitely be supported.

I'll file a bug. Thanks for finding it.


I don't think this is going to be possible without creating
System.Int32Array, System.StringArray, etc.

Example:

int[] array1 = new int[100];
string[] array2 = new string[50];

Both of these objects (array1 and array2) are of type System.Array. How
can one of them implement IList<int> and the other implement
IList<string>? How could the compiler have any way of knowing which
interfaces are implemented by which instances?

There just isn't a way for two instances of the same type to implement
different interfaces; it breaks way too many OOP rules.
Nov 16 '05 #6
Kevin,

You misunderstood the implication that I was making. Basically, because
System.Array (the general base for all arrays) implements IList, and
IEnumerable, the specialized arrays (int[], string[], etc, etc) should also
implement the specialized versions (IList<int> and IEnumerable<int>) as
well.

Also, array1 and array2 are not of type System.Array. Rather, they
derive from System.Array. Because of this, it is easy for the derivation to
implement IList<T>.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kevin P. Fleming" <kp*******@backtobasicsmgmt.com> wrote in message
news:ud*************@TK2MSFTNGP09.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
Sherif,

Given that System.Array implements IList and IEnumerable, the
specialized versions should definitely be supported.

I'll file a bug. Thanks for finding it.


I don't think this is going to be possible without creating
System.Int32Array, System.StringArray, etc.

Example:

int[] array1 = new int[100];
string[] array2 = new string[50];

Both of these objects (array1 and array2) are of type System.Array. How
can one of them implement IList<int> and the other implement
IList<string>? How could the compiler have any way of knowing which
interfaces are implemented by which instances?

There just isn't a way for two instances of the same type to implement
different interfaces; it breaks way too many OOP rules.

Nov 16 '05 #7
Nicholas Paldino [.NET/C# MVP] wrote:
You misunderstood the implication that I was making. Basically, because
System.Array (the general base for all arrays) implements IList, and
IEnumerable, the specialized arrays (int[], string[], etc, etc) should also
implement the specialized versions (IList<int> and IEnumerable<int>) as
well.

Also, array1 and array2 are not of type System.Array. Rather, they
derive from System.Array. Because of this, it is easy for the derivation to
implement IList<T>.


OK, I did not realize that array1 and array2 would be instances of a
type derived from System.Array. Is this true whenever I declare any
array? I was not aware that the C# compiler created hidden types to be
used to implement arrays. I guess it must, otherwise array1[0] would be
a System.Object, not a System.Int32.

Given this information, implementing the IList and IEnumerator generics
would be relatively easy and quite useful.

Nov 16 '05 #8
Kevin,

This is true when you delcare any array. Your array type is T[]. The
base of T[] is System.Array.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kevin P. Fleming" <kp*******@backtobasicsmgmt.com> wrote in message
news:uU*************@tk2msftngp13.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
You misunderstood the implication that I was making. Basically, because System.Array (the general base for all arrays) implements IList, and
IEnumerable, the specialized arrays (int[], string[], etc, etc) should also implement the specialized versions (IList<int> and IEnumerable<int>) as
well.

Also, array1 and array2 are not of type System.Array. Rather, they
derive from System.Array. Because of this, it is easy for the derivation to implement IList<T>.


OK, I did not realize that array1 and array2 would be instances of a
type derived from System.Array. Is this true whenever I declare any
array? I was not aware that the C# compiler created hidden types to be
used to implement arrays. I guess it must, otherwise array1[0] would be
a System.Object, not a System.Int32.

Given this information, implementing the IList and IEnumerator generics
would be relatively easy and quite useful.

Nov 16 '05 #9
Hello

"Kevin P. Fleming" <kp*******@backtobasicsmgmt.com> wrote in message
news:ud*************@TK2MSFTNGP09.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:

There just isn't a way for two instances of the same type to implement
different interfaces; it breaks way too many OOP rules.


Although int[] and string[] inherit from System.Array, they are not the same
type. System.Array implements the non generic IList, so int[] should
implement IList<int> and string[] should implement IList<string>

Best regards,
Sherif
Nov 16 '05 #10
Hello

Sorry for any inconvenience, but I think people using released version of c#
are intrested in future versions as well.

Best regards,
Sherif

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:#P*************@TK2MSFTNGP09.phx.gbl...
Please, post whidbey questions to the private whidbey NG, This NG is for
released products.

Willy.

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
Hello

I was just got VS 2005 preview, and was trying generics.

I tried the following code

int[] intArray = new int[100];
IList<int> intList = (IList<int>) intArray;

it didn't compile, also the following didn't compile

IEnumerable<int> intEnumerable = (IEnumerable<int>)intArray;

IMHO it makes perfect sense that int[] should implement IList<int>,
IEnumerable<int>, etc, since it implements the non-generic IList, and
IEnumerable.

Best regards,
Sherif


Nov 16 '05 #11
Thanks

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eC**************@TK2MSFTNGP09.phx.gbl...
Sherif,

Given that System.Array implements IList and IEnumerable, the
specialized versions should definitely be supported.

I'll file a bug. Thanks for finding it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
Hello

I was just got VS 2005 preview, and was trying generics.

I tried the following code

int[] intArray = new int[100];
IList<int> intList = (IList<int>) intArray;

it didn't compile, also the following didn't compile

IEnumerable<int> intEnumerable = (IEnumerable<int>)intArray;

IMHO it makes perfect sense that int[] should implement IList<int>,
IEnumerable<int>, etc, since it implements the non-generic IList, and
IEnumerable.

Best regards,
Sherif


Nov 16 '05 #12
Hi,
Sorry, but I have to disagree,those really interested in future versions can
also subscribe to the private Whidbey NG's., and those actually having
issues with this new stuff, will find better answers in the Whidbey NG's
(MSFT PM are actively monitoring these NG's). And don't forget that we are
talking about pre-alpha code here, nothing is carved in stone yet, some
might really get confused when reading messages about un-released stuff in
public NG's.

Willy.
"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:et**************@TK2MSFTNGP11.phx.gbl...
Hello

Sorry for any inconvenience, but I think people using released version of
c#
are intrested in future versions as well.

Best regards,
Sherif

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:#P*************@TK2MSFTNGP09.phx.gbl...
Please, post whidbey questions to the private whidbey NG, This NG is for
released products.

Willy.

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
> Hello
>
> I was just got VS 2005 preview, and was trying generics.
>
> I tried the following code
>
> int[] intArray = new int[100];
> IList<int> intList = (IList<int>) intArray;
>
> it didn't compile, also the following didn't compile
>
> IEnumerable<int> intEnumerable = (IEnumerable<int>)intArray;
>
> IMHO it makes perfect sense that int[] should implement IList<int>,
> IEnumerable<int>, etc, since it implements the non-generic IList, and
> IEnumerable.
>
> Best regards,
> Sherif
>
>



Nov 16 '05 #13
Hello

I am corrected. Sorry for the inconvenience.

Best regards,
Sherif

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:OV*************@TK2MSFTNGP10.phx.gbl...
Hi,
Sorry, but I have to disagree,those really interested in future versions can also subscribe to the private Whidbey NG's., and those actually having
issues with this new stuff, will find better answers in the Whidbey NG's
(MSFT PM are actively monitoring these NG's). And don't forget that we are
talking about pre-alpha code here, nothing is carved in stone yet, some
might really get confused when reading messages about un-released stuff in
public NG's.

Willy.
"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:et**************@TK2MSFTNGP11.phx.gbl...
Hello

Sorry for any inconvenience, but I think people using released version of c#
are intrested in future versions as well.

Best regards,
Sherif

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:#P*************@TK2MSFTNGP09.phx.gbl...
Please, post whidbey questions to the private whidbey NG, This NG is for released products.

Willy.

"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
> Hello
>
> I was just got VS 2005 preview, and was trying generics.
>
> I tried the following code
>
> int[] intArray = new int[100];
> IList<int> intList = (IList<int>) intArray;
>
> it didn't compile, also the following didn't compile
>
> IEnumerable<int> intEnumerable = (IEnumerable<int>)intArray;
>
> IMHO it makes perfect sense that int[] should implement IList<int>,
> IEnumerable<int>, etc, since it implements the non-generic IList, and
> IEnumerable.
>
> Best regards,
> Sherif
>
>



Nov 16 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by jack112 | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.