C# Array Exists() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

In C#, Array.Exists answers a yes/no question: does any element pass this test? It returns true or false.

Use Exists when you do not need the element or index—only whether a match is present. Under the hood it stops at the first success.

This is a static member of System.Array. You call it with the class name, such as Array.Exists(...). Arrays in C# have a fixed length after creation; use List<T> when the count must grow.

Syntax

Pass the array and predicate; use the bool directly in an if.

C#
bool ok = Array.Exists(nums, x => x < 0);
CallWhat it does
Array.Exists(nums, x => x < 0)True if any negative int exists.
Array.Exists(names, n => n == "Bob")True if Bob is present.

TrueForAll asks whether every element matches. Find returns the element itself.

Library declarations
C#
public static bool Exists<T>(T[] array, Predicate<T> match);

Parameters

ParameterDescription
arrayRequired. Array to test.
matchRequired. Predicate for a matching element.

Return Value

Return ValueDescription
trueAt least one element matched.
falseNo element matched.

C# Examples

Example 1 — Any Negative Number?

Check whether the array contains a value below zero.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 3, -1, 8 };
        bool hasNeg = Array.Exists(nums, x => x < 0);
        Console.WriteLine(hasNeg);
    }
}

How It Works

  1. Predicate. x < 0 is the test.
  2. Hit at -1. Exists can stop immediately.
  3. Bool result. True means “yes, something matched.”
  4. No index. Call FindIndex if you need where.

Example 2 — False When None Match

All positive numbers → Exists is false.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 1, 2, 3 };
        Console.WriteLine(Array.Exists(nums, x => x < 0));
    }
}

How It Works

  1. Full scan. Every element was tested.
  2. All fail. Result is false.
  3. Clean if. if (Array.Exists(...)) reads well.
  4. Empty array. Exists on Length 0 is also false.

Example 3 — Any Name Starting With C

Combine Exists with string methods inside the lambda.

C#
using System;

class Program {
    static void Main() {
        string[] names = { "Ann", "Bob", "Cara" };
        bool ok = Array.Exists(names, n => n.StartsWith("C"));
        Console.WriteLine(ok);
    }
}

How It Works

  1. StartsWith. Cara matches.
  2. Short-circuit. No need to check further after Cara.
  3. Readable intent. “Does any name start with C?”
  4. Case sensitive. Default StartsWith cares about case.

Frequently Asked Questions

true if any element matches the predicate; otherwise false.
Exists returns a bool. Find returns the element or default.
Exists asks “any?”. TrueForAll asks “all?”.
Yes. It can return true as soon as one element matches.
Exists returns false because no element matched.

Next: Fill()

Set every element (or a range) to the same value with System.Array.

Fill() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful