VbNet · Console
imports System
imports System.Collections.Generic
Imports System.Linq
Public Class Program
Public Shared Sub Main()
Dim lista As New List(Of MeuObjeto)()
Dim obj1 As New MeuObjeto()
obj1.Codigo = 1
obj1.Nome = "Pedro"
obj1.Alterado = False
'ao instanciar o objeto buscando do banco, essa propriedade deve estar "false"
lista.Add(obj1)
Dim obj2 As New MeuObjeto()
obj2.Codigo = 2
obj2.Nome = "Sonia"
obj2.Alterado = False
'ao instanciar o objeto buscando do banco, essa propriedade deve estar "false"
lista.Add(obj2)
lista.FirstOrDefault(Function(f) f.Codigo = 2).Nome = "Maria"
Dim alterados As List(Of MeuObjeto) = lista.Where(Function(f) f.Alterado = True).ToList()
For Each obj As MeuObjeto In alterados
Console.WriteLine(obj.Nome & Convert.ToString(" foi alterado"))
Next
Console.ReadLine()
End Sub
End Class
Public Class MeuObjeto
Private _codigo As Integer
Private _nome As String
Public Property Codigo() As Integer
Get
Return _codigo
End Get
Set
If _codigo <> value Then
Alterado = True
End If
_codigo = value
End Set
End Property
Public Property Nome() As String
Get
Return _nome
End Get
Set
If _nome <> value Then
Alterado = True
End If
_nome = value
End Set
End Property
Public Property Alterado() As Boolean
Get
Return m_Alterado
End Get
Set
m_Alterado = Value
End Set
End Property
Private m_Alterado As Boolean
End Class