user2294434
user2294434

Reputation: 163

How to remove a class property which is a list of another class

I need to remove an item form a generic list, which is actually a list of of another class, in VB.net ?

Below is my class, how to achieve the following?

  1. From the settings class, I want to remove the section that has the name as "Three":
  2. next I want to return only the section that has the name as "Three" and not the other section values?
Public Class Settings

    Public Property Sections As List(Of Section)

End Class

Public Class Section

    Public Property Name As String
 
    Public Property Age As Int
 
    Public Property addesss As String

End Class

Upvotes: 0

Views: 231

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54417

The RemoveAll method allows you to find items that match specific criteria and remove them:

mySettings.Sections.RemoveAll(Function(s) s.Name = "Three")

The argument is a lambda expression that matches Section objects with a Name property equal to "Three".

Upvotes: 2

Related Questions