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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:02:50+00:00 2026-05-18T10:02:50+00:00

I have the following class which is quite wide usely throughout my application :

  • 0

I have the following class which is quite wide usely throughout my application :

public class ResultStatus
{
  public Int32 Id {get; protected set}

  public ErrorCode ErrorCode {get; protected set;}

  List<string> UserMessages {get; protected set;}

  protected ResultStatus (Int32 id, ErrorCode errorCode, List<string> userMessages)
  {
    Id = id;
    ErrorCode = errorCode;
    UserMessages = userMessages;
  }

  public static ResultStatus Success (int32 id, ErrorCode errorCode, IEnumerable<string> userMessages)
 {
   ResultStatus resultStatus = new ResultStatus (id, errorCode, userMessages.ToList());

   return resultStatus;

 }
}

I am concerned with the casting from the IEnumerable type of the parameter to List() and Im thinking of changing the property UserMessages type from List to IEnumerable to avoid the cast.
However in the projects that use this class, sometimes a Count is applied or the list is accessed directly by index. So what I gain by avoiding a cast, I loose by using the Count of the IEnumerable for instance which iterates throughout the collection. What is the nice way of doing this? Leave it like this, List type property – parameter casting from IEnumerable to List or change the type of the property and not be concerned on the few Counts ?

  • 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-18T10:02:51+00:00Added an answer on May 18, 2026 at 10:02 am

    To internally store the information you need to use a List<T> or a similar structure. You can’t just save the IEnumerable<T> you got passed in. The enumerable might not be valid once the function returns, or it might only allow iterating once,…

    As for the type of public properties I like using ReadOnlyCollection<T>.

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

Sidebar

Related Questions

I have a class which must implement the following property public ICollection<IType> Items {
I have following component composition: public interface IJob { ILogger Logger { get; set;
I have the following class which handles my user logged in / logged out
I have the following asynctask class which is not inside the activity. In the
I have the following javascript class which I am trying to pass to an
In Java I have created the following class which extends ImageView to create a
I have the following tricky problem: I have implemented a (rather complicated) class which
Let's say I have the following class hierarchy: TaskViewer inherits from ListViewer<Task> which in
I have a class which loads an xml file using the following: Path.Combine( AppDomain.CurrentDomain.BaseDirectory,
I have following situation - Have a MongoService class, which reads host, port, database

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.