Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7745783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:06:37+00:00 2026-06-01T10:06:37+00:00

How to give another function’s returned value in LINQ. I have a IEnumerable of

  • 0

How to give another function’s returned value in LINQ.

I have a IEnumerable of objects(Say ObjColl). From that object collection, I have to filter the objects based on the return value of another function(say GetObjPropertyValue). My final output should be Dictionary of object and its propertyValue. This dictionary shouldn’t have the objects for which propertyvalue is nothing.

GetObjPropertyValue function takes Object as input and return its property as string. But some times it returns nothing if that property not exist on Objects.

My query is something like,

Dictionary(obj, string)=ObjColl.Where(Function(p) not GetObjPropertyValue(p) is nothing)

but in above query I should write code to store the return value of GetObjPropertyValue(p) and add obj-p and returnValue combination to the dictionary. How to write that??

For Example See below code:

The last line below code is wrong. but please suggest me how to correct it. My intention is, I want output collection(say dictionary) of each fruitname and its color(returned by other function call) for all the fruits which the GetFruitColor is not nothing(it can be empty or valid string).

[code] Private function GetFruitColor(fruit) as string
‘It returns fruit color.
‘If valid fruit and color not available, it returns “”(empty string)
‘If fruit is not valid Fruit, it returns nothing. End function

private sub MyMethod()
  Create a list of strings.
        Dim fruits As New List(Of String)(New String() _
                                {"apple", "passionfruit", "banana", "mango", _
                                 "orange", "blueberry", "grape", "strawberry"})

Dim query = _fruits.Where(Function(fruit) k= GetFruitColor(fruit) if not k is nothing select fruit, k) 
End Sub

In above code last line is wrong. So how to put getFruitColor in k, how to correct it to save the k value and give me output as dictionary of fruit and k value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:06:39+00:00Added an answer on June 1, 2026 at 10:06 am

    I would suggest:

    • Project to an anonymous type consisting of (fruit, color)
    • Filter out “nothing” colors
    • Create dictionary

    In C# this would be:

    var query = fruits.Select(fruit => new { fruit, color = GetFruitColor(fruit) })
                      .Where(pair => !string.IsNullOrEmpty(pair.color))
                      .ToDictionary(pair => pair.fruit, pair => pair.color);
    

    Adjust accordingly for VB 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that takes 2 returned variables from another function to write
I have a playlist file which give me another playlist file which also give
Example: I have a selector like this, which I give to another method as
Give that I have written a JPanel with many different components on it, is
Suppose I have a function (foo) defined as (defun foo () (read-from-minibuffer What? ))
I made a static function that returns me an ArrayList of objects: allThread =(ArrayList)
I have a recursive lambda function in one of my objects, and it needs
A class implements a public function that calculates some value. During the calculation the
I have a few functions that deal with lists. I have an even function
I made a system that creates a simple string with Function/Response format, example: Check('Value'):ShowImage(@)|Check('Value'):OtherFunction(@)....and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.