SoFunction
Updated on 2025-03-06

C# Method to query elements in an array with a specific character using linq statement

This article describes the method of using linq statements to query elements in an array starting with a specific character. Share it for your reference. The details are as follows:

The following code queryes elements in the array that start with the letter k

using System;
using ;
using ;
using ;
static void Main(string[] args)
{
  string[] names = {"kaka","kunka","kumar","James","Smith"};
  var queryResults =
  from n in names
  where ("k")
  select n;
  ("Names beginning with K:");
  foreach (var item in queryResults) {
    (item);
  }
  ();
}

The output result is as follows:

kaka
Kunka
Kumar

I hope this article will be helpful to everyone's C# programming.