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

  • Home
  • SEARCH
  • 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 6047945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:24:29+00:00 2026-05-23T07:24:29+00:00

I have Ienumerable<string> collection that I want to concatenate into a single string with

  • 0

I have Ienumerable<string> collection that I want to concatenate into a single string with delimitor ;

for instance {“One”,”Two”,”Three”} -> “One;Two;Three;”

is it possible to do using the following function?

List<string> list = new List<string>(){"One","Two","Three"};
list.Aggregate<String>((x,y) => x + String.Format("{0};",y));

I have tried also this code:

list.Aggregate<String>((x,y) => String.Format("{0};{1}",x,y)); 

both samples didn’t work.

EDIT: I see that it is not possible to do what I wanted using Linq-2-sql or Aggregate function in Linq-2-sql.

http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/dac496c0-5b37-43ba-a499-bb8eff178706/

EDIT2: the workaround I used is to go over the items returned by the original linq query…and copies them to a new list and do the join as suggested in the answers below on a linq object and not linq-2-sql object.

  • 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-23T07:24:29+00:00Added an answer on May 23, 2026 at 7:24 am

    You can just use String.Join for this. If you’re using .NET4 then you can use the overload that takes an IEnumerable<string> directly:

    string joined = string.Join(";", list);
    

    If you’re using an older version of the framework then you’ll need to use the overload that takes a string[] array instead, converting your collection to an array first if necessary:

    string joined = string.Join(";", list.ToArray());
    

    EDIT…

    Of course, if you really want to use Aggregate for some reason then there’s nothing stopping you. If so, it’s usually recommended to build your string using a StringBuilder rather than multiple string allocations:

    string joined = list.Aggregate(new StringBuilder(),
                                   (sb, s) => sb.Append(s).Append(';'),
                                   sb => (sb.Length > 0) ? sb.ToString(0, sb.Length - 1)
                                                         : "");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an IEnumerable<IEnumerable<T>> collection that I want to convert to a single dimension
I have a collection of IEnumerable<sentence> (sentence = string) I want to split all
I have a function that returns IEnumerable<IEnumerable<string>> . I want to use this function,
I have a method that returns an IEnumerable<KeyValuePair<string, ArrayList>> , but some of the
I have an IEnumerable<DirectoryInfo> that I want to filter down using an array of
I have a class that contains a collection. I want to provided a method
I have a class that inherits from Dictionary<string, string> . Within an instance method,
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,

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.