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

Bootstrap Modal Popup keep open on PostBack in ASP.Net

Resolved Issue in Asp core 3.0 serializersettings does not exist in AddJsonOptions

.Net most asked interview questions for experienced professionals (C#,Asp WEBFORM,MVC,ASP CORE,WEB API,SQL Server,Java Script,Jquery)