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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:53:10+00:00 2026-05-23T14:53:10+00:00

for long time , I always append a string in the following way. for

  • 0

for long time , I always append a string in the following way.

for example if i want to get all the employee names separated by some symbol , in the below example i opeted for pipe symbol.

string final=string.Empty;

foreach(Employee emp in EmployeeList)
{
  final+=emp.Name+"|"; // if i want to separate them by pipe symbol
}

at the end i do a substring and remove the last pipe symbol as it is not required

final=final.Substring(0,final.length-1);

Is there any effective way of doing this.

I don’t want to appened the pipe symbol for the last item and do a substring again.

  • 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-23T14:53:11+00:00Added an answer on May 23, 2026 at 2:53 pm

    Use string.Join() and a Linq projection with Select() instead:

    finalString = string.Join("|", EmployeeList.Select( x=> x.Name));
    

    Three reasons why this approach is better:

    1. It is much more concise and readable
      – it expresses intend, not how you
      want to achieve your goal (in your
      case concatenating strings in a
      loop). Using a simple projection with Linq also helps here.

    2. It is optimized by the framework for
      performance: In most cases string.Join() will
      use a StringBuilder internally, so
      you are not creating multiple strings that are
      then un-referenced and must be
      garbage collected. Also see: Do not
      concatenate strings inside loops

    3. You don’t have to worry about special cases. string.Join()
      automatically handles the case of
      the “last item” after which you do
      not want another separator, again
      this simplifies your code and makes
      it less error prone.

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

Sidebar

Related Questions

Long-time joelonsoftware follower, 1st-time stackoverflow poster. I want to know how safely I can
Long time reader never posted until now. Im having some trouble with Android, im
A long time ago I had the following directory structure in my SVN repository
For a long time, I always thought that the bs and count parameters for
I've used capistrano for a long time, but always for sites that weren't critical.
This question's been bugging me for a long time. I've always wondered how game
For a long time I've noticed that adjusting line-height and adding some extra space
For long time, I was always thinking that parameters in Perl subs are passed
Installing third-party components always take a long time specially if you have large ones,
I've been using xampp for a long time and it's always worked fine. I

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.