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

  • Home
  • SEARCH
  • 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 6687899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:20:32+00:00 2026-05-26T05:20:32+00:00

I have a Foreach loop and every iteration puts the record into a system.

  • 0

I have a Foreach loop and every iteration puts the record into a system. Then I also have a foreach loop that gets the data from a linqQuery. I want to iterate through each one and compare the FullName of each and if its true it makes a bool as true and if not it marks it as false. How would I go about doing that. This is what I have so far.

    foreach (Lead p in sessionleads)
    {

        string AccountName = "";
        string AccountId = "";
        string ContactId = "";
        bool b = false;
        foreach (var a in linqQuery)
        {
            AccountName = a.AccountName.ToString();
            AccountId = a.AccountId.ToString();
            ContactId = a.ContactId.ToString();

            if (AccountName.ToString() == p.AccountName.ToString())
            {
                b = true;
            }
            else
            {
                b = false;
            }
        }


        if (b == true)
        {
            Entity opportunity = new Entity("opportunity");
            opportunity["new_contact"] = new EntityReference("contact", new Guid(ContactId));
            opportunity["customerid"] = new EntityReference("account", new Guid(AccountId));
            opportunity.FormattedValues["new_leadstatus"] = p.Status;
            opportunity.FormattedValues["statuscode"] = p.Type;

            //opportunity["ownerid"] = 
            Guid opportunityId = orgService.Create(opportunity);

        }
        else
        {
            Entity opportunity = new Entity("opportunity");
            opportunity["new_contact"] = new EntityReference("contact", contactId);
            opportunity["customerid"] = new EntityReference("account", accountId);
            opportunity.FormattedValues["new_leadstatus"] = p.Status;
            opportunity.FormattedValues["statuscode"] = p.Type;

            //opportunity["ownerid"] = 
            Guid opportunityId = orgService.Create(opportunity);
        }

    }

Thanks!

  • 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-26T05:20:32+00:00Added an answer on May 26, 2026 at 5:20 am

    Add a break after the first check:

    if (AccountName.ToString() == p.AccountName.ToString())
    {
        b = true;
        break;
        ...
    

    Even better:

    var item = (from i in linqQuery 
                where i.AccountName == p.AccountName 
                select i).FirstOrDefault();
    bool found = (item != null);
    if(found)
    {
       ....
    }
    else
    {
       ....
    }
    

    Then, the use that to do the rest of the logic checks.

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

Sidebar

Related Questions

I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
i have two foreach loop to display some data, but i want to use
in a ASP.NET application (MVC) I have a foreach loop that loops through a
I have a function which performs a foreach loop on an array from a
So I have a for loop that does an iteration of a SQL stored
So...I have this scenario where I have a Foreach loop that loops through a
I have a foreach loop that looks like this: foreach (var line in theCP4UnknownList.Distinct())
i want to have a foreach loop where the initial array is changed inside
In Java 5 and above you have the foreach loop, which works magically on
I know I'm probably missing something easy, but I have a foreach loop 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.