472,805 Members | 3,289 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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
13 2571
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
5
by: pmatos | last post by:
Hi all, I have a vector of vector of ints, I could use C approach by using int but I think C++ vector<vector<int> > would be easier to manage. So I have a function which creates and initializes...
10
by: Piotr | last post by:
I have a class 'Statistics' which has a private attribute ' vector<int>* _x;' And in the destructor of the Statistics, I have this code to free the memory: Statistics::~Statistics() { if...
2
by: per9000 | last post by:
Hi, *background* I want a class containing an int (a list of sets of integer). This should be hidden for the user and he/she should be able to insert his/her favourite data structure so to be a...
10
by: arnuld | last post by:
It is quite an ugly hack but it is all I am able to come up with for now :-( and it does the requires work. I want to improve the program, I know you people have much better ideas ;-) /* C++...
10
by: arnuld | last post by:
WANTED: /* C++ Primer - 4/e * * Exercise: 9.26 * STATEMENT * Using the following definition of ia, copy ia into a vector and into a list. Use the single iterator form of erase to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.