Wednesday, 17 April 2019

Linq Query

#region RepeatableStringcount
            string input = "TRYARABT";
            var grouped = input.GroupBy(x => x).Where(c=>c.Count()>1).Select(group => new {
                                                                                                                  word =group.Key,
                                                                                                                  count = group.Count()
                                                                                                                                                    });
            var outputList= grouped.ToDictionary(x => x.word, x => x.count);
           
            foreach (var output in outputList)
            {
                Console.WriteLine(output.Key + " Count:- " + output.Value);
            }

 #endregion

#region Find 2nd highest salary

var secondHighestSalary= employess.GroupBy(sal=> new{sal.EmployeeName,sal.Salary})
.OrderByDescending(F=>F.Key.Salary)
.Skip(1).First().Select(emp=>new {EmployeeName=emp.Key.EmployeeName,Salary=emp.key.Salary})

#EndRegion

static void Main(string[] args)
 { 
 
 var inputs =new [] { "abcd", "dcba", "cabd", "xyz", "yxz", "uml" };

      var result = find(inputs.ToList());

 }

 public static List<List<string>> find(List<string> strList)

        {

            return strList.GroupBy(s => string.Concat(s.OrderBy(c => c))).Select(gr => gr.ToList()).ToList();

        }

No comments:

Post a Comment