how to make a program which checks and count occurrences Value in An Array in c#

In this article, I will show, how to make a program which checks and count occurrences value in an Array  in c#


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace testconsole

{
    class Program
    {
     
        static void Main(string[] args)
        {

            int[] myArray = new int[] { 1, 2, 3, 4, 5, 6, 2, 2 };

            string chekvalue = "";
            for  (int i = 0; i < myArray.Length-1; i++)

            {
            if (chekvalue.Contains(myArray[i].ToString()))
                {
                }
                else {
                    chekvalue = myArray.Length-1 + chekvalue;
                    Console.Write(myArray[i] + " : ");
                    int count = 0;

                for (int j = 0; j < myArray.Length - 1; j++)

                {

                    if (myArray[i] == myArray[j])

                    {

                        count++;

                    }

                }

                Console.WriteLine(count);
                }
               
            }

            Console.ReadLine();

         
            }

       
     
        }
     
    }


 

   




Comments

Popular posts from this blog

Dynamic Mega Menu With Asp.Net with c#,java script and Sql Server.

Bootstrap Modal Popup keep open on PostBack in ASP.Net

Export div content to PDF Using ITextSharp in asp.net