Saturday, 2 December 2017

C# Program to Split a String Collections into Groups


Code:

using System;
using System.IO;
using System.Collections;
using System.Linq;
class program
{
    static void SendEmail(string email)
    {        
        Console.WriteLine(email);
    }
    static void Main(string[] args)
    {
        string[] email = {"One@aaa.com", "Two@aaa.com",
                        "Three@aaa.com", "Four@aaa.com",
                        "Five@aaa.com", "Six@aaa.com",
                        "Seven@aaa.com", "Eight@aaa.com"};
        var Grp = from i in Enumerable.Range(0, email.Length)
                       group email[i] by i / 3;
        foreach (var mail in Grp)
            SendEmail(string.Join(";", mail.ToArray()));
       Console.ReadLine();
    }
}


Output:

One@aaa.com;Two@aaa.com;
Three@aaa.com;Four@aaa.com;
Five@aaa.com;Six@aaa.com;
Seven@aaa.com;Eight@aaa.com



More C# Programs:

















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...