Q:

C# program to check a specified number exists in an array using Linq

belongs to collection: C# LINQ Programs

0

C# program to check a specified number exists in an array using Linq

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to check a specified number exists in the array using Linq, is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to check a specified number exists 
//in an array using Linq.

using System;
using System.Linq;

class LinqDemo
{
    static void Main(string[] args)
    {
        float[] numbers = { 8.2F, 11.2F, 7.6F, 8.3F, 5.5F, 6.4F };

        bool isExist = false;

        isExist = numbers.Contains(12.5F);

        if(isExist==true)
            Console.WriteLine("Number is exist in the array");
        else
            Console.WriteLine("The number does not exist in the array");
    }
}

Output:

The number does not exist in the array
Press any key to continue . . .

Explanation:

In the above program, we created a class LinqDemo that contains Main() method, In the Main() method we created an array of a float number.

The Contains() method is used to check the specified number is exist in an array or not. Here, 12.5F number does not exist in the array then it will print "Number does not exist in the array" message on the console screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# LINQ Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to check a specified city exists in the... >>
<< C# program to join multiple data sources using Lin...