Skip to content

Finding count of particular items from a list #5

@marcialwushu

Description

@marcialwushu

I have a List<String> with 1000 names. I want to find out the count of names which is starting with letter "S".

What will be the best option to do it?

If Linq is available

using System.Linq;
list.Where(s=>s!=null && s.StartsWith("S")).Count();

if Linq is not available.

int count=0;
foreach (string s in list) {
  if (s!=null && s.StartsWith("S")) count++;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions