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

The Archive Base Latest Questions

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

var r = from s in tempResult select Encoding.GetEncoding(iso-8859-1).GetBytes(s); I understand, this returns IEnumerable<byte[]>

  • 0
 var  r = from s in tempResult    
          select Encoding.GetEncoding("iso-8859-1").GetBytes(s);

I understand, this returns IEnumerable<byte[]>, but I looking for LINQ way to convert the whole IEnumerable<byte[]> to byte[].

  • 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-24T12:23:57+00:00Added an answer on May 24, 2026 at 12:23 pm

    None of the answers provided so far will work, because they will convert the IEnumerable<byte[]> to byte[][]. If your goal is to take all of the arrays in the enumerable and produce one big array, try this:

    byte[] result = r.SelectMany(i => i).ToArray();
    

    See this ideone example.


    Note that this is not the most efficient way to do this. It would be faster to convert the original query result to a list, then compute the sum of the array lengths. Once that is done, you can allocate the final array immediately, then make one more pass over the result list and copy each result array’s contents into the larger array.

    The above LINQ query definitely makes this task easy, but it will not be fast. If this code becomes a bottleneck in the application, consider rewriting it this way.


    I might as well provide an example of a more efficient implementation:

    public static T[] JoinArrays<T>(this IEnumerable<T[]> self)
    {
        if (self == null)
            throw new ArgumentNullException("self");
    
        int count = 0;
    
        foreach (var arr in self)
            if (arr != null)
                count += arr.Length;
    
        var joined = new T[count];
    
        int index = 0;
    
        foreach (var arr in self)
            if (arr != null)
            {
                Array.Copy(arr, 0, joined, index, arr.Length);
                index += arr.Length;
            }
    
        return joined;
    }
    

    Note that whatever enumerable you pass in will be enumerated twice, so it would be a good idea to pass in a list or an array instead of a query, if that query is expensive.

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

Sidebar

Related Questions

var cityList = from country in doc.Element(result) .Element(cities) .Descendants(city) select new { Name =
This query works great: var pageObject = (from op in db.ObjectPermissions join pg in
This is my Jquery <script type=text/javascript> $(function() { var from = $.session(from); var to
For the following code var validate = from P in this.DataContext.Persons where P.UserName.Equals(login) &&
I have this json var from google api : $json=' { kind: webfonts#webfontList, items:
I have this regular expression: var from = result.match(/^From\:(.*)/m)[1].replace(/^\s+/, ''); The problem is that
var from = 2012-01-13 T11:00:00; Date date = parseDate(from); How can I convert this
I've got a problem when I'm calling a static var from another class. I
var auditAgencyRecords = (from ag in db.Agencies join ara in db.AuditRuleAccounts on ag.Agency_Id equals
var result = from lr in _db.LeaveRequest join th in _db.TotalHourslu on lr.TotalHoursEffect equals

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.