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

  • SEARCH
  • Home
  • 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 393695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:16:59+00:00 2026-05-12T16:16:59+00:00

Note: This is similar, but not quite the same as this other question I’ve

  • 0

Note: This is similar, but not quite the same as this other question

I’ve implemented an IBusinessCollection interface. It dervies from both ICollection<T>, and the old-busted non-generic ICollection. I’d prefer to just dump the old busted ICollection, but I’m using WPF databinding with a CollectionView which wants me to implement the old-busted non-generic IList 🙁

Anyway, the interfaces look like this:

public interface IBusinessCollection<T> : ICollection<T>, ICollection
{ }

public interface ICollection<T>
{ int Count { get; } }

public interface ICollection
{ int Count { get; } }

Due to using Dependency Injection, I’m passing around objects of type IBusinessCollection<T> using their interfaces, not by concrete types, so I have something like this:

internal class AnonymousCollection : IBusinessCollection<string>
{ 
    public int Count { get { return 5; } }
}

public class Factory
{
    public static IBusinessCollection<string> Get()
    { return new AnonymousCollection(); }
}

When I try and call this code, I get an error, as follows:

var counter = Factory.Get();
counter.Count; // Won't compile
// Ambiguity between 'ICollection<string>.Count' and 'ICollection.Count'

There are 3 ways to make this compile, but all of them are ugly.

  1. Cast the class to it’s concrete implementation (which I may not know)

  2. Cast the class explicitly to ICollection

  3. Cast the class explicitly to ICollection<T>

Is there a fourth option which doesn’t require me to cast things at all? I can make whatever changes I need to IBusinessCollection<T>

  • 1 1 Answer
  • 5 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-05-12T16:16:59+00:00Added an answer on May 12, 2026 at 4:16 pm

    This appears to solve the issues in my quick tests.

    public interface IBusinessCollection<T> : ICollection<T>, ICollection
    {
        new int Count { get;  }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Note: This question is very similar, but not quite the same.] I'm trying to
Note: This is similar to this question but it is not the same. I
[NOTE: This questions is similar to but not the same as this one .]
I realize that there are other posts asking similar questions, but do not quite
Note: I've asked this question in a similiar format on superuser but it seems
Note: This question has broadened in scope from previous revisions. I have tried to
Note: this is in relation to android specifically, but the best answer might not
Note this question was originally posted in 2009, before C++11 was ratified and before
Note: this is not real information: $ ssh-keygen -t rsa -C "tekkub@gmail.com" Generating public/private
Note: This code actually codes from a tutorial book I'm reading at the moment,

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.