Email Address সেমিকোলন দিয়ে আলাদা করা এরকম একটা string আমাদের কাছে আছে -
string UserInputEmails = "aa@xyz.com;cc@abc.com;bb@abc.com;dd@abc.com";
একটা c# program লিখতে হবে, প্রতিটি Domain এর under এ কতগুলো করে email Address আছে তার একটা লিস্ট দেখাবে। উপরের UserInputEmails এর জন্য program এর output হবে এইরকম-
Domain = xyz.com & Count = 1
Domain = abc.com & Count = 3
using System;
using System.Collections.Generic;
using System.Linq;
namespace MainPrograms
{
public class Program
{
public static void Main(string[] args)
{
// User List of emails seperated by semi colon. You can have as many
// number of emails you want in this string.
string UserInputEmails =
"aa@xyz.com;cc@abc.com;bb@abc.com;cc@abc.com";
// Split the string into a string array.
string[] UserEmails = UserInputEmails.Split(';');
// Select only the domain part of the emails into a string array,
// using substring() function
string[] UserdDomain= UserEmails.
Select(x=>x.Substring(x.LastIndexOf("@")+1)).ToArray();
// Group the emails by email domain,
// and select the Domain and respective count
var Result = UserdDomain.GroupBy(x => x).
Select(y=>new { Domain=y.Key,Count=y.Count()});
// Finally print the domain name and the emails count
foreach (var item in Result)
{
Console.WriteLine("Domain={0} & Count={1}",item.Domain,item.Count);
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment