using System.Collections.Generic;
static List<int> allAttachments = new List<int>() { 2,3,5 };
static List<int> emailAttachments = new List<int>();
static int maxAttachmentSize = 10;
static int remainingSize = maxAttachmentSize;
static int prevAttachmentSize = 0;
public static void Main()
private static void checkEmailAttachments()
if (allAttachments[0] <= remainingSize)
emailAttachment = allAttachments[0];
remainingSize = remainingSize - allAttachments[0];
allAttachments.RemoveAt(0);
else if (allAttachments[0] > remainingSize )
emailAttachment = allAttachments[0] - (allAttachments[0] - remainingSize);
int secondSplitEmail = allAttachments[0] - emailAttachment;
allAttachments[0] = secondSplitEmail;
prevAttachmentSize = emailAttachment;
emailAttachments.Add(emailAttachment);
if (remainingSize <= 0 || allAttachments.Count == 0 || (allAttachments.Count > 0 && (allAttachments[0] + prevAttachmentSize) > maxAttachmentSize))
sendEmail(emailAttachments);
emailAttachments.Clear();
remainingSize = maxAttachmentSize;
if (allAttachments.Count > 0)
private static void sendEmail(List<int> emailAttachments)
Console.WriteLine("Email Attachements");
foreach (var email in emailAttachments)
Console.WriteLine(email);