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 7019825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:14:09+00:00 2026-05-27T23:14:09+00:00

Following the rules that a public APIs should never return a list , i’m

  • 0

Following the rules that a public APIs should never return a list, i’m blinding converting all code that returned lists, to return ICollection<T> instead:

public IList<T> CommaSeparate(String value) {...}

becomes

public ICollection<T> CommaSeparate(String value) {...}

And although an ICollection has a Count, there is no way to get items by that index.

And although an ICollection exposes an enumerator (allowing foreach), i see no guarantee that the order of enumeration starts at the “top” of the list, as opposed to the “bottom”.

i could mitigate this by avoiding the use of ICollection, and instead use Collection:

public Collection<T> Commaseparate(String value) {...}

This allows the use of an Items[index] syntax.

Unfortunately, my internal implementation constructs an array; which i can be cast to return IList or ICollection, but not as a Collection.

Is there a ways to access items of a collection in order?

This begs the wider question: Does an ICollection even have an order?


Conceptually, imagine i want to parse a command line string. It is critical that the order of items be maintained.

Conceptually, i require a contract that indicates an “ordered” set of string tuples. In the case of an API contract, to indicate order, which of the following is correct:

IEnumerable<String> Grob(string s)

ICollection<String> Grob(string s)

IList<String> Grob(string s)

Collection<String> Grob(string s)

List<String> Grob(string s)
  • 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-05-27T23:14:10+00:00Added an answer on May 27, 2026 at 11:14 pm

    The ICollection<T> interface doesn’t specify anything about an order. The objects will be in the order specified by the object returned. For example, if you return the Values collection of a SortedDictionary, the objects will be in the the order defined by the dictionary’s comparer.

    If you need the method to return, by contract, a type whose contract requires a certain order, then you should express that in the method’s signature by returning the more specific type.

    Regardless of the runtime type of the object returned, consider the behavior when the static reference is IList<T> or ICollection<T>: When you call GetEnumerator() (perhaps implicitly in a foreach loop), you’re going to call the same method and get the same object regardless of the static type of the reference. It will therefore behave the same way regardless of the CommaSeparate() method’s return type.

    Additional thought:

    As someone else pointed out, the FXCop rule warns against using List<T>, not IList<T>; the question you linked to is asking why FXCop doesn’t recommend using IList<T> in place of List<T>, which is another matter. If I imagine that you are parsing a command-line string where order is important, I would stick with IList<T> if I were you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method and interface: public object ProcessRules(List<IRule> rules) { foreach(IRule rule
What are the rules regarding function Overloading? I have the following code: public T
Consider the following code (for simplicity, I did not follow any C# coding rules).
I have the following code to enable validation work: $(document).ready(function() { $(#eventForm).validate({ rules: {
I'm working on the following LINQ query: public void GetAuditRuleAgencyRecords(IEnumerable<Entities.AuditRule> rules) { using (LinqModelDataContext
One question regarding whether the following code should yield a compiler warning or not
Consider the following code. public interface IFoo { } public class Bar { public
I'm redirecting all non www urls to www. for that i've used the following
I have the following classes that represent tables: public class PriceDefinition { public virtual
I have the following .htaccess to rewrite my domain.com/ to domain.com/public/ # Rewrite rules

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.