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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:54:56+00:00 2026-05-22T14:54:56+00:00

LINQ to Objects supports queries on string objects but when I use code such

  • 0

LINQ to Objects supports queries on string objects but when I use code such as below:

string SomeText = "this is some text in a string";
return SomeText.Take(6).ToString();

All I get is:

System.Linq.Enumerable+<TakeIterator>d__3a`1[System.Char]

This is discussed as an “accident” in this question but this is what I am actually trying to do and I cannot find it through search anywhere.

I know there are other ways to manipulate strings but then I also know you can do some really cool tricks with LINQ and I just would like to know if there is a way to trim a string to a certain length with LINQ?

  • 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-22T14:54:57+00:00Added an answer on May 22, 2026 at 2:54 pm

    There’s no method built in to System.Linq to do this, but you could write your own extension method fairly easily:

    public static class StringExtensions
    {
        public static string ToSystemString(this IEnumerable<char> source)
        {
            return new string(source.ToArray());
        }
    }
    

    Unfortunately, because object.ToString exists on all .NET objects, you would have to give the method a different name so that the compiler will invoke your extension method, not the built-in ToString.

    As per your comment below, it’s good to question whether this is the right approach. Because String exposes a lot of functionality through its public methods, I would implement this method as an extension on String itself:

    /// <summary>
    /// Truncates a string to a maximum length.
    /// </summary>
    /// <param name="value">The string to truncate.</param>
    /// <param name="length">The maximum length of the returned string.</param>
    /// <returns>The input string, truncated to <paramref name="length"/> characters.</returns>
    public static string Truncate(this string value, int length)
    {
        if (value == null)
            throw new ArgumentNullException("value");
        return value.Length <= length ? value : value.Substring(0, length);
    }
    

    You would use it as follows:

    string SomeText = "this is some text in a string";
    return SomeText.Truncate(6);
    

    This has the advantage of not creating any temporary arrays/objects when the string is already shorter than the desired length.

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

Sidebar

Related Questions

I am using WCF to send some Linq objects across the wire. I want
I use LINQ to Objects instructions on an ordered array. Which operations shouldn't I
I'm working with LINQ to objects and have a function where in some cases
see also Differences between LINQ to Objects and LINQ to SQL queries We are
I'd like to serialize some LINQ generated objects and store them in a table
I asked this question reguarding the use of Linq-2-Sql with the Rob Conery's use
Due to the potential differences between Linq-to-Entities (EF4) and Linq-to-Objects, I need to use
I use linq to objects and I find out .ToList and .ToArray operation is
I remember seeing a video with Jon Skeet reimplementing Linq-to-Objects a while back but
I have two LINQ objects which have exactly the same columns and I would

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.