Q:

C# program to find the negative double numbers from the list of objects using Linq

belongs to collection: C# LINQ Programs

0

C# program to find the negative double numbers from the list of objects 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 find the negative double numbers using Linq is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# Program to find negative double numbers from 
//the list of objects using Linq.

using System;
using System.Linq;
using System.Collections.Generic;

class Demo
{
    static void Main(string[] args)
    {
        List<object> objectList = new List<object>()
        {
            101, "Amit", 102,"Joseph", -10.3, "RK Verma", 104, "Sanjay Shukla", 10.5F, "Pramod Pandey",-10.7
        };


        List<double> result = objectList.OfType<double>().Where(n=>n<0).ToList();

        foreach (double neg in result)
        {
            Console.WriteLine(neg + " ");
        } 
    }
}

Output:

-10.3
-10.7
Press any key to continue . . .

Explanation:

In the above program, we created a list of objects that contains different types of values then we find negative double numbers using OfType() and Where() method using the below code.

List<double> result = objectList.OfType<double>().Where(n=>n<0).ToList();

 

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 demonstrate the example of Linq Inte... >>
<< C# program to find string values from the list of ...