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 7636219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:37:10+00:00 2026-05-31T07:37:10+00:00

Is it possible to do the below requirement in C# 4.0 Current: I have

  • 0

Is it possible to do the below requirement in C# 4.0

Current:
I have a data provider class which queries the DB/XML/ExternalDataSource
As shown below, the function PerformQuery takes two params and returns a list of type Result.

In my client application the instance of DataProvider call to PerformQuery will create the list and return.

Objective:
If the query result of PerformQuery is more (ex. 100K) then the user will have to wait.
So I can either create a backgroundworker and the process the list returned by PerformQuery.

But I want to know if the PerformQuery can return each item in its foreach statement to the caller function in sync or async mode. Instead of waiting to build the entire list in the foreach statement and again processing the list in client application.

Caller–>PerformQuery(a,b)
^ |
| |
| | Send back each result item to the caller function.
<———<


    class DataProvider
    {
       public List PerformQuery(string param1, string param2)
       {
           List m_res = new List();

           var m_queryRes = DataAccessor.GetResults(param1, param2);

           foreach(var res in m_queryRes)
           {    
                  Result result = new Result();
                  result.Name = res.FirstName + res.SecondName;
                  result.Code = res.Code + "Some business logic";
                  m_res.Add(result);              
           }

           return m_res;
       }
    }
    class Result
    {
       Property Name;
       Property Code;
    }

  • 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-05-31T07:37:11+00:00Added an answer on May 31, 2026 at 7:37 am

    You should consider using iterators, with iterators you can return each element at a time based on the request of the caller.

    class DataProvider
    {
       public System.Collections.IEnumerable<Result> PerformQuery(string param1, string param2)
       {
           var m_queryRes = DataAccessor.GetResults(param1, param2);
    
           foreach(var res in m_queryRes)
           {    
                  Result result = new Result();
                  result.Name = res.FirstName + res.SecondName;
                  result.Code = res.Code + "Some business logic";
                  yield return result;            
           }
    
       }
    }
    class Result
    {
       Property Name;
       Property Code;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am told that the configuration below is possible, but have had significant difficulty
Is it possible to access outer local varialbe in a PHP sub-function? In below
Within a C++ class hierarchy, is it possible to enforce a requirement that a
Is the below requirement possible? How to make 10 different version of the same
Is it possible to make a modification as specified in the class below, and
Currently I have a JQuery script in place http://jsfiddle.net/gaby/zzj7E/5/ which handles the requirement that
Is below possible using WSO2 IS? I have gone through different WSO2 blogs. They
It's possible to declare variables with the below structure in C++ private: public: protected:
Is it possible to get rid of the eval statement below? The code below
Is it possible to get list after Session.Close as below? var bundles = session.Linq<Bundle>();

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.