c# count number of occurrences in string
char myChar = 'x';
string myString = "xyz";
int count = myString.Count(s => s == myChar);
c# count number of occurrences in string
char myChar = 'x';
string myString = "xyz";
int count = myString.Count(s => s == myChar);
C# Program For Check Total Occurrence Of A Number In An Array
using System;
using System.Linq;
namespace CheckOccurrenceOfNumberInArray
{
class Program
{
static void Main(string[] args)
{
int[] array = { 1, 20, 15, 23, 15, 14, 26, 188,175,12, 36, 78, 15, 3, 5, 91, 822, 100, 1202, 78, 95, 12, 123, 12, 14, 25, 36, 15, 36, 95, 45, 10, 20, 30, 04, 50, 40, 60, 70, 80, 90, 104 };
Console.WriteLine("Your Array...");
for (int i = 0; i < array.Length; i++)
{
Console.Write(array[i] + " ");
}
Console.WriteLine("\n\n");
Console.Write("Enter number to check occurrence : ");
int number = Convert.ToInt32(Console.ReadLine());
int occurrences = array.Count(x => x == number);
Console.WriteLine("Occurrence of {0} in given array is {1}", number, occurrences);
Console.ReadKey();
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us