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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:53:33+00:00 2026-05-14T08:53:33+00:00

public class InvestorMailing { public string To { get; set; } public IEnumerable<string> Attachments

  • 0
public class InvestorMailing
{
    public string To { get; set; }

    public IEnumerable<string> Attachments { get; set; }

    public int AttachmentCount { get; set; }

    public long AttachmentSize { get; set; }
}

i have an IList<InvestorMailing> mailingList. if the attachment size is greater than x, then i need to split my object into chunks. is there an easy linq-y way to do this?

Edited:

this is how i’m generating my mailings:

        var groupedMailings = mailingList.GroupBy(g => g.GroupBy);

        var investorMailings = groupedMailings.Select(
            g => new DistinctInvestorMailing
            {
                Id = g.Select(x => x.Id).FirstOrDefault(),
                To = g.Key.Trim(),
                From = g.Select(x => x.From).FirstOrDefault(),
                FromName = g.Select(x => x.FromName).FirstOrDefault(),
                Bcc = g.Select(x => x.Bcc).FirstOrDefault(),
                DeliveryCode = g.Select(x => x.DeliveryCode).FirstOrDefault(),
                Subject = g.Select(x => x.Subject).FirstOrDefault(),
                Body = g.Select(x => x.Body).FirstOrDefault(),
                CommentsOnStatus = g.Select(x => x.CommentsOnStatus).FirstOrDefault(),
                Attachments = g.Select(x => x.AttachmentPath),
                AttachmentCount = g.Select(x => x.AttachmentPath).Count(),
                AttachmentSize = g.Sum(x => x.AttachmentSize),
                MailType = g.Select(x => x.MessageType).FirstOrDefault()
            }
        ).ToList();
  • 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-14T08:53:34+00:00Added an answer on May 14, 2026 at 8:53 am

    It should be pretty simple to do it with a standard method. Consider this example:

    class Foo
    {
        public Foo(int weight) { Weight = weight; }
        public int Weight { get; set; }
    }
    

    …

    IEnumerable<IList<Foo>> GroupFoosByWeight(IList<Foo> foos, int weightLimit)
    {
        List<Foo> list = new List<Foo>();
        int sumOfWeight = 0;
    
        foreach (Foo foo in foos)
        {
            if (sumOfWeight + foo.Weight > weightLimit)
            {
                yield return list;
                sumOfWeight = 0;
                list.Clear();
            }
    
            list.Add(foo);
            sumOfWeight += foo.Weight;
        }
    
        if (list.Count > 0)
            yield return list;
    }
    

    …

    List<Foo> foos = new List<Foo>()
    {
        new Foo(15), new Foo(32), new Foo(14), new Foo(19), new Foo(27)
    };
    
    foreach (IList<Foo> list in GroupFoosByWeight(foos, 35))
    {
        Console.WriteLine("{0}\t{1}", list.Count, list.Sum(f => f.Weight));
    }
    

    Edit

    I worked on it a bit and produced a LINQ version. It doesn’t really save much code in this case, but it’s a start.

    int weightLimit = 35;
    int fooGroup = 0;
    int totalWeight = 0;
    
    Func<Foo, int> groupIncrementer = f =>
    {
        if (totalWeight + f.Weight > weightLimit)
        {
            fooGroup++;
            totalWeight = 0;
        }
    
        totalWeight += f.Weight;
    
        return fooGroup;
    };
    
    var query = from foo in foos
                group foo by new { Group = groupIncrementer(foo) }
                    into g
                    select g.AsEnumerable();
    
    foreach (IList<Foo> list in query)
    {
        Console.WriteLine("{0}\t{1}", list.Count, list.Sum(f => f.Weight));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.