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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:29:27+00:00 2026-06-05T09:29:27+00:00

I have this IEnumerable of type Question.. the class Question has the properties, Question(string)

  • 0

I have this IEnumerable of type Question.. the class Question has the properties, Question(string) and Id(int)

What I want to do is if the question of any object in the IEnumerable has a length > 25
then “Substring” it and add “…”

So my idea was something like:

ienumQuestions.Where(e=>e.Question.Length > 25).Change(e.Question=>e.Question.Substring(25)+"...");

Now im not sure if that syntax was 100% correct but I hope you get the point..

Is there wanyway to do this?.. i really dont want to create a loop for this.. since I simply dont like loops 🙂

Thanks in advance!

  • 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-05T09:29:28+00:00Added an answer on June 5, 2026 at 9:29 am

    Approach with caution

    You could use the renowned ForEach extension method in LINQ to iterate through each item and action it accordingly. Essentially it’s the same as the Change method you described, and could look something like this:

    ForEach LINQ Extension Method

    public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource> action)
    {
        foreach(TSource item in source)
        {
            action(item);
        }
    }
    

    Implementation

    ienumQuestions.Where(e => e.Question.Length > 25).ForEach(e =>
    {
        e.Question = e.Question.Substring(0, 25) + "...";
    });
    
    // or
    ienumQuestions.ForEach(e =>
    {
        if (e.Question.Length > 25)
        {
            e.Question = e.Question.Substring(0, 25) + "...";
        }
    });
    

    Argument and Extra Reading

    I personally dislike the approach of using the ForEach LINQ extension to directly update the objects, I prefer to use it for reference purposes only. I would strongly recommend reading “foreach vs ForEach” before adopting it though, as essentially it goes against the principal of LINQ in the sense that it directly modifies objects within the collection, which is what LINQ was not originally intended to do.

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

Sidebar

Related Questions

I have a method with this signature: IEnumerable<string> GetCombinations(string s, int length) And I
I have this method to transfer files using a FTP Server: private void TransferNeededFiles(IEnumerable<string>
the ToSelectList method I have: public static IList<SelectListItem> ToSelectList<T>(this IEnumerable<T> itemsToMap, Func<T, string> textProperty,
I have a datagrid who's ItemsSource is a strongly typed IEnumerable object In this
i have created the folloiwng view model class public class viewmodelclass { public IEnumerable<Question>
EDIT The bare-bones version of this question is, if I have some object o
I have this following IEnumerable LINQ query: var query = from p in Enumerable.Range(2,
I have this issue with ComboBox that uses IEnumerable<Brush> as ItemsSource; the problem lies
Say I have this simple method: public IEnumerable<uint> GetNumbers() { uint n = 0;
I have an IEnumerable< T> which is declared on the page like this: IEnumerable<

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.