Count Occurrences of a Character in a String in C#
To count occurrences of a character inside a string we can use lambda expression methodCount()
using (Linq).Example
using System;
using System.Linq;
public class Program
{
public static void Main()
{
string source = "hello World";
int count = source.Count(char => char == 'l');
Console.WriteLine(count);
}
}
Output
3