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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:23:54+00:00 2026-06-14T18:23:54+00:00

I would like to compare two classes that look like this public class Order

  • 0

I would like to compare two classes that look like this

public class Order
{
        public string KundNummer, KundNamn, ErReferens, VarReferens, KontraktsNummer, Betvillk, Levvillk, Levsatt, Speditor,
            Resenh, Projekt, OrderDatum, LeveransDatum, ErtOrdernr, LagerbokfDatum, KundPostAdr, KundPostAdr2, KundGLN, KundPostnr, 
            KundOrt, KundLandKod, KundLand, KundVATnr, KundDistrikt, KundSaljare, KundText1, KundText2, KundText3, KundSprak,
            KundValuta, KundRabattAvtal, KundRabattAvtalBenamning, KundPrislista, KundPrislistaBenamning, KundALnamn, KundALpostAdr, KundALpostAdr2, KundALGLN, KundALpostnr, KundALort,
            KundALlandKod, KundALland;
        public double OrderNummer, Fakturarabatt, Frakt, Expavg, Brutto, Netto, ExklMoms, Totalt, Moms, Avrundn, KundValutaKurs, KundValutaEnhet;
        public int EUPeriodSamman, InklMoms, EjKlar, Levererad, Malukerad, BestallningSkapad, Ordererk,
            Plocklista, Foljesedel, ExtraOrderdokument, Restorder, Faktura, KundSparaText, KundExport, KundRantefakturering, KundKravbrev,
            KundKravavgift, KundRestnoteraEj, KundSamlingsfakturera;
    }

i want to compare two objects of this class for logging which fields in my database that changed.

public string OrderUppdateraOrder(Order order)
    {
        Order OrderToCompare = new Order();
        OrderToCompare = OrderVisaOrderInformation(order.OrderNummer);

        //then the code goes on to make the changes to the database from the class order
        //while OrdertoComapre still have the values from before this function was called
    }

So is it possible to loop through these classes and compare them or do I have to write an if for every variable in my class? 🙂

Or maybe convert it to a List? I don’t know? 😛

Thank you for answers

  • 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-14T18:23:55+00:00Added an answer on June 14, 2026 at 6:23 pm

    i want to log if there is a difference and log the difference something like this CustomerNumber: changed from 456 to 345

    The best option is probably just to use reflection to crawl over the public properties and fields, comparing them. This will have less code to compare, but will have a performance overhead. You can greatly reduce that overhead using tools like FastMember:

    static class Program {
        static void Main()
        {
            Order o1 = new Order { Resenh = "abc" },
                  o2 = new Order { Resenh = "abc" };
            ShowDiffs(o1, o2); // {nothing}
            o2.Resenh = "def";
            ShowDiffs(o1, o2); // Resenh changed from abc to def
        }
        static void ShowDiffs<T>(T x, T y)
        {
            var accessor = TypeAccessor.Create(typeof(T));
            if (!accessor.GetMembersSupported) throw new NotSupportedException();
            var members = accessor.GetMembers();
    
            foreach (var member in members)
            {
                object xVal = accessor[x, member.Name],
                       yVal = accessor[y, member.Name];
                if (!Equals(xVal, yVal))
                {
                    Console.WriteLine("{0} changed from {1} to {2}",
                        member.Name, xVal, yVal);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to be able to compare two classes derived from the same
I have two arrays that I would like to compare and ultimately wind up
I would like to compare two versions of a class. I have used WinDiff,
I have two arrays of strings that I would like to compare for equality:
I have two chunks of text that I would like to compare and see
I would like to compare two columns in the same table. I want to
I would like to know if there is anyway I can compare two columns
I have two images which i would like to compare and do different operations
I'm looking to compare two varchars in SQL, one would be something like Cafe
I would like to compare 4 character string using wildcards. For example: std::string wildcards[]=

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.