Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:59:38+00:00 2026-06-11T10:59:38+00:00

For a very long time I was curious about the following: int[] array =

  • 0

For a very long time I was curious about the following:

int[] array = new int[1];
int iArrayLength = array.Length;    //1

Since arrays implement the IList interface, the following is allowed:

int iArrayCount = ((IList<int>)array).Count;    //still 1

BUT:

int iArrayCount = array.Count;  //Compile error. WHY?
int iArrayLength = array.Length;    //This is what we learned at school!

The question:
How can an array implement IList<T> (especially the int Count { get; } property from IList<T>) without allowing it to be used on the base class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:59:40+00:00Added an answer on June 11, 2026 at 10:59 am

    This is known as an explicit interface member implementation. The interface member is not exposed as a public member of the type, but it is available by casting the reference to the interface type.

    This can be done in C# like this:

    interface I
    {
        void M();
    }
    
    class C : I
    {
        public int P { get; set; }
        void I.M() { Console.WriteLine("M!"); }
    }
    

    Then you can use these types like this:

    C obj = new C();
    obj.P = 3;
    ((I)obj).M();
    

    But this won’t compile:

    obj.M();
    

    As JeffN825 notes, one reason for implementing the interface members explicity is that they’re not supported by the type. For example, Add throws an exception (relevant discussion). Another reason for implementing a member explicity is that it duplicates another public member with a different name. That’s the reason Count is implemented explicitly; the corresponding public member is Length. Finally, some members are implemented implicitly, namely, the indexer. Both of these lines work (assuming arr is an array of int):

    arr[0] = 8;
    ((IList<int>)arr)[0] = 8;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck at this since a very long time. tell me if the following
The following simple query takes a very long time (several minutes) to execute. I
I have a number of very long arrays. No run-time sort is possible. It
It's been a very long time since I coded in C, and I've spent
It's a very long time since I've looked at anything in the mobile world
Its been a while since I worked in asp.net and a very long time
I am currently doing the following join and it takes a very long time
Unfortunately after very long time i'm re-posting again about the same problem: org.apache.jasper.JasperException: The
I have a MySql query that take a very long time to run (about
I have this problem for a very long time, but we are about to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.