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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:25:02+00:00 2026-06-06T10:25:02+00:00

Question on searching for records in nested classes. Here’s a cut down version of

  • 0

Question on searching for records in nested classes. Here’s a cut down version of my code. Hopefully it explains enough! I’m using Visual Web Developer 2010 Express.

Class

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

namespace API
{
    public class Fixture
    {
        public int ID { get; set; }
        public string Description { get; set; }
        public List<FixturesMarketData> FixturesMarketData;

        public Fixture()
        {
            FixturesMarketData = new List<FixturesMarketData>();
        }

        public void AddMarket(int _fixtureID, int _marketID, string _MarketName)
        {
            FixturesMarketData.Add(new FixturesMarketData ( _fixtureID, _marketID, _MarketName ));
        }

        public string ListMarkets()
        {
            string strReturn="";
            foreach (var item in FixturesMarketData)
             {
                strReturn = strReturn + "<br />" + item.marketDescription + " - " + item.marketID + " - " + item.fixtureID;
            }
            return strReturn;
        }
    }

    public class FixturesMarketData
    {
        public int fixtureID { get; set; }
        public int marketID { get; set; }
        public string marketDescription { get; set; }

        public FixturesMarketData(int _mdfixtureID, int _mdmarketID, string _mdmarketDescription)
        {
            fixtureID = _mdfixtureID;
            marketID = _mdmarketID;
            marketDescription = _mdmarketDescription;
        }
    }
}

Main Code

_fixtures = new List<Fixture>();
_fixtures.Add(new Fixture { ID = 1234, Description = 'This is a test' });

int index = _fixtures.FindIndex(Fixture => Fixture.ID.Equals(1234));
_fixtures[index].AddMarket(1234, 5678, 'This is a test market');
AddToOutputString(_fixtures[index].ListMarkets());

So basically this would result in:
Fixture:

ID= 1234;
Description=This is a test;
FixturesMarketData
FixtureID=1234;
MarketID=5678;
marketDescription=This is a test market;

How do I do a find on FixturesMarketData for where market id equals 5678?

I can do it like this:

var index=-1;
            foreach (var item in _fixtures)
            {
                index = item.FixturesMarketData.FindIndex(entry => entry.marketID.Equals(_marketId));
                if(index!=-1)
                {
                    break;
                }
            }

but I’m guessing there must be a way to do it in Lambda Find style

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-06-06T10:25:03+00:00Added an answer on June 6, 2026 at 10:25 am
    var enumerable=_fixtures.Where(x=>x.FixturesMarketData.Any(x=>x.marketId==5678));
    

    now if you hope to find many such fixtures you can do

    enumerable.ToList();
    

    if you want only the first one then

    enumerable.FirstOrDefault();
    

    and if only one fixture can be found then

    enumerable.SingleOrDefault();
    

    Note: Here Default means if not found return NULL else there will be an error thrown

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

Sidebar

Related Questions

Searching here I found that this question was already asked , but I think
I've spent hours searching the web for an answer to this question... Here's what
Two-headed question here guys, First, I've been trying to do some searching for a
I have one question about searching and counting files in directories and subdirectories. I
I came across this question after searching for a ODBC or JDBC. To my
The question is rather straightforward but not answered by searching. How do I determine
I know this question can be answered by searching in google. But I have
Sorry if this question is answered somewhere else but I tried searching several pages
I've been searching around trying to find an answer to this question, and I
I have a simple question, but I'm searching for longer time, but I always

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.