473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

System.Int32[] hides IList implemetation? How?

I noticed somthing. The native Array Types implement the IList
interface. However they do not contain all the methods in the
interfaces they implement. for example...

int[] test=new int[100];
test.Add(5); <<<< This is a Compile Error

However

if(test is IList)
{
IList list=test;
list.Add(123);
}

Comiles Just fine and causes a runtime exception when Add is called.

How is this possible?! Is there a way to hide methods of an interface
when you implement it?

Thomas

Nov 22 '05 #1
2 1561
When you implement a method of an interface you have two options:
public int Add(object value) {} // Makes the method part of your class
(implicit)
int IList.Add(object value) {} // Method only accessible through the
interface (explicit)

Note that someone can still call the explicit method by casting your class
to the interface type:
int[] test=new int[100];
IList testList = (IList) test;
testList.Add(5);

<ts******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I noticed somthing. The native Array Types implement the IList
interface. However they do not contain all the methods in the
interfaces they implement. for example...

int[] test=new int[100];
test.Add(5); <<<< This is a Compile Error

However

if(test is IList)
{
IList list=test;
list.Add(123);
}

Comiles Just fine and causes a runtime exception when Add is called.

How is this possible?! Is there a way to hide methods of an interface
when you implement it?

Thomas

Nov 22 '05 #2
Makes Sense. Thank you very much.

Sean Hederman wrote:
When you implement a method of an interface you have two options:
public int Add(object value) {} // Makes the method part of your class (implicit)
int IList.Add(object value) {} // Method only accessible through the interface (explicit)

Note that someone can still call the explicit method by casting your class to the interface type:
int[] test=new int[100];
IList testList = (IList) test;
testList.Add(5);

<ts******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I noticed somthing. The native Array Types implement the IList
interface. However they do not contain all the methods in the
interfaces they implement. for example...

int[] test=new int[100];
test.Add(5); <<<< This is a Compile Error

However

if(test is IList)
{
IList list=test;
list.Add(123);
}

Comiles Just fine and causes a runtime exception when Add is called.
How is this possible?! Is there a way to hide methods of an interface when you implement it?

Thomas


Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

83
by: kartik | last post by:
there seems to be a serious problem with allowing numbers to grow in a nearly unbounded manner, as int/long unification does: it hides bugs. most of the time, i expect my numbers to be small. 2**31...
2
by: tsteinke | last post by:
I noticed somthing. The native Array Types implement the IList interface. However they do not contain all the methods in the interfaces they implement. for example... int test=new int;...
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
3
by: Chris | last post by:
Hi, the specs for System.Array are : public abstract class Array : ICloneable, IList, ICollection, IEnumerable but I can't use any of the functions presented by IList in my code ...
6
by: Bern McCarty | last post by:
I'm trying to use the VS 2005 March Tech Preview and am trying to adjust some MC++ to the new C++/CLI syntax. I got a little hung up when I encountered the below error. Certainly my...
1
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by...
1
by: henrycortezwu | last post by:
Hi All, I'm trying to connect to a virtual port (COM19, OUTGOING, "Bluetooth Serial Port") using VS2005 System.IO.Ports. When I ran the ff code below here's what happens. 1) VS2005 Compiles w/o...
4
by: Roger Aikin | last post by:
I've converted a VB6 project to VB.Net 2005. (Actually using vstudio pro 2005). I'm on a machine that also has VB6 and Vstudio.net 2003 on it. The project uses Word, Excel, MapPoint and SqlClient...
6
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
2
by: Tony | last post by:
Hello! According to the documentation we have the following interface IList : ICollection, IEnumerable { I can understand all the methods in this IList } interface ICollection : IEnumerable...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.