Identical objects with same value fields returning different C#

Asked

Viewed 23 times

0

Identical objects with equal fields returning different when comparing with Equals or ==

var oldPayments = orderNotTrack.Payments
                .Where(p => p.Status == Status.Activated)
                .Select(p => new OrderPayment()
                {
                    Guid = p.Guid,
                    CardFlagName = p.CardFlagName,
                    TransactionAmount = Math.Round(p.TransactionAmount, 2),
                    ChangeMoney = p.ChangeMoney,
                    Type = p.Type
                })
                .ToList();
            
            var newPayments = order.Payments.Where(p => p.Status == Status.Activated)
                .Select(p => new OrderPayment()
                {
                    Guid = p.Guid,
                    CardFlagName = p.CardFlagName,
                    TransactionAmount = Math.Round(p.TransactionAmount, 2),
                    ChangeMoney = p.ChangeMoney,
                    Type = p.Type
                })
                .ToList();

I’m comparing denial, in case they’re different Follow image of the objects: Objeto 0

Objeto1

1 answer

1


Objects that are not pointed by the same memory address are considered different What can be done is override the class Equals If it is a list you can create a list class of the object to be compared thus also overriding your equals Peace

Browser other questions tagged

You are not signed in. Login or sign up in order to post.