Tech Study

Write a program in C# to display the number and frequency of number from given array in LINQ Query

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

using System;
using System.Linq;
using System.Collections.Generic;
 
class LinqExercise
{
    static void Main(string[] args)
    {
        int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 4, 5, 2, 3, 10 };       
        Console.Write("The numbers in the array  are : \n");
        Console.Write("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 4, 5, 2, 3, 10 \n");
 
        var n = from x in arr
                group x by x into y
                select y;
        Console.WriteLine("\nThe number and the frequency are : \n");
        foreach (var arrno in n)
        {
            Console.WriteLine("Number " + arrno.Key + " appears " + arrno.Count() + " times");
        }
        Console.ReadLine();
    }
}

Result

Write a program in C# to display the number and frequency of number from given array in LINQ Query
Write a program in C# to display the number and frequency of number from given array in LINQ Query

TaggedWrite a program in C# to display the number and frequency of number from given array in LINQ Query

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more