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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:17:03+00:00 2026-05-15T10:17:03+00:00

Do not expose generic lists IF all my methods, need to expose a collection,

  • 0

Do not expose generic lists

IF all my methods, need to expose a collection, then I need to user the Linq Extension .ToList(), almost everywhere I need to use lists, or user Collections in all my code.

If that’s the case, .ToList() is ignoring the rule right? Or is there a technique like copying the list o something to fix the violation and still return a list?

  • 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-15T10:17:03+00:00Added an answer on May 15, 2026 at 10:17 am

    I disable that rule because I don’t feel like it’s a valid one. If you want to return a collection which contains an O(1) count and is not a direct reference to an internal field, List<T> is the best choice.

    I don’t deeply understand your case here but it sounds like you have a method which returns a LINQ query over some internal data. If that’s the case then using a .ToList() on the data is appropriate since you likely don’t want future modifications of your internal fields to affect the return value of a method. In that case, there is no reason to not expose it as a List<T>.

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

Sidebar

Related Questions

Possible Duplicate: C#: Difference between List<T> and Collection<T> (CA1002, Do not expose generic lists)
It seems that there is a guidance that a model should not expose its
It's not uncommon to see Python libraries that expose a universal opener function, that
If I need to translate my website in languages that I do not know,
Not ever sure if it can be done, but is it possible to use
Not crazy about the way Xcode 4.2 has laid out the files on disk.
Not able to download artifacts from central maven repository. <mirrors> <!-- mirror | Specifies
Not quite sure how to go about describing what it is I'm trying to
Not sure whats going on here, or what could be the integer in this
Not to sound like a koan, but just wondering if there are definite 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.