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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:31:43+00:00 2026-05-15T23:31:43+00:00

I have the following setup: Class A property x as string property y as

  • 0

I have the following setup:

Class A
      property x as string
      property y as int
      property z as String

End Class

Class CollOfA
    inherits List(Of A)

End Class

What I would like is an Item property in the collection that I can say:

dim c as new CollOfA
c.item("this", 2, "that")

I have tried implementing the following in CollOfA:

Class CollOfA
    inherits List(Of A)

    Default Public Overridable Shadows ReadOnly Property Item(ByVal x As String, ByVal y As Integer, byval z as string)
        Get
            ' I want to do something like:
            ' ForEach item in me see if anything matches these three things

        End Get
    End Property
End Class

I know about predicates, but I am struggling with how to set the criteria of the predicate (i.e. passing x, y, and z).

Has anyone implemented something similar?

  • 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-15T23:31:44+00:00Added an answer on May 15, 2026 at 11:31 pm

    Here’s two ways that I came up with to accomplish your question. One way uses a LINQ query syntax to filter; the second uses a custom object to hold your predicate parameters and then uses that object to perform the filter.

    Using the LINQ syntax in your Item property:

    Default Public Overridable Shadows ReadOnly Property Item(ByVal x As String, ByVal y As Integer, ByVal z As String) As IEnumerable(Of A)
        Get
            Return (From theA In Me
                    Where (theA.x = x And theA.y = y And theA.z = z)
                    Select theA)
    
        End Get
    End Property
    

    The other way would be to create a PredicateParameter class to hold your parameters and also a delegated method that is used to execute the filter. I saw this on an MSDN comment – here’s the link. Here’s the class:

    Class PredicateParams
    
        Public Sub New(ByVal theA As A)
            Criteria = theA
        End Sub
    
        Public Property Criteria As A
    
        Public Function IsMatch(ByVal theA As A) As Boolean
            Return (theA.x = Criteria.x And theA.y = Criteria.y And theA.z = Criteria.z)
        End Function
    
    End Class
    

    And here’s the property that is in the CollOfA class that uses it:

    Public Overridable Shadows ReadOnly Property ItemPred(ByVal x As String, ByVal y As Integer, ByVal z As String) As IEnumerable(Of A)
        Get
            Dim predA As New A
            predA.x = x
            predA.y = y
            predA.z = z
    
            Dim pred As New PredicateParams(predA)
    
            Return Me.FindAll(AddressOf pred.IsMatch)
        End Get
    
    End Property
    

    Lastly, here’s a console runner to test this.

    Sub Main()
        Dim mycoll As New CollOfA()
    
    
        For index = 1 To 100
            Dim anA As New A()
            anA.x = (index Mod 2).ToString()
            anA.y = index Mod 4
            anA.z = (index Mod 3).ToString()
            mycoll.Add(anA)
        Next
    
        Dim matched As IEnumerable(Of A) = mycoll.Item("1", 3, "2")
        Dim matched2 As IEnumerable(Of A) = mycoll.ItemPred("1", 3, "2")
    
        Console.WriteLine(matched.Count.ToString())  'output from first search
        Console.WriteLine(matched2.Count.ToString()) 'output from second search (s/b same)
        Console.ReadLine()
    
    End Sub
    

    Hopefully this helps. There may be a more elegant way to do this, but I didn’t see one. (BTW, I generally work with C#, so my VB.NET is a little rusty.)

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

Sidebar

Related Questions

I have a TextBox bound to a ViewModel's Text property with the following setup:
I have the following setup: Code on my local machine (OS X) shared as
How do you setup a multi-developer XDebug PHP environment? I have the following setup:
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have a class that I use to setup objects in an array. In
I am working on my first NHibernate project, and have the following setup/requirement. I
Currently I have use the following approach to setup change notification on any of
I have the following setup (which works fine). Using CodeFirst (CTP4). A template has

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.