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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:11:54+00:00 2026-06-01T01:11:54+00:00

I have a silly question here. I define a class with many data members,

  • 0

I have a silly question here.
I define a class with many data members, like this:

public class A
{
    public string Name { get; set; }
    public double Score { get; set; }
    //...many members
    public C Direction { get; set; }
    public List<B> NameValue1 { get; set; }
    public List<string> NameValue2 { get; set; }
    //...many members
}

Now, I’m writing unit test code and want to compare two instances of class A.
But I found this doesn’t work:

Assert.AreEquals(a1, a2);

I must override Equals method to do that? C# can’t help with this by default?
Or I can serialize these two guys and compare the filestream?

Thank you.

  • 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-01T01:11:55+00:00Added an answer on June 1, 2026 at 1:11 am

    The default equality implementation, for reference types, is reference equality: “is this the same instance”. For equivalence, yes, you should write that yourself if you need that, but: it is rarely all that useful really (and there’s a problem, because if you override Equals you should override GetHashCode too, with a suitably parallel implementation.

    Personally, I’d compare manually in your unit test if this code isn’t part of your main system.

    Lists are a pain too, since there are three options:

    • same list instance
    • different lists with same content instances
    • different lists with equivalent content instances

    You probably mean the last, but that is the same problem, repeated.

    Re serialization: that is tricky too, since it depends on the serializer and the contents. I wouldn’t recommend that route unless a: your type is already being used for serialization, and b: your chosen serializer guarantees the semantic you mean. For example, BinaryFormatter does not (I can provide a concrete example if you want, but trust me: this is not guaranteed).

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

Sidebar

Related Questions

This is probably a silly question, but here it goes.Imagine you have the following
This may be a silly question but... Say you have a sentence like: The
This is probably a silly question but here goes: I like to be able
Okay, Now admittedly this sounds like a silly question; But, I actually have a
Probably a silly question here but I have been trying to find this for
Sorry for asking silly question.. I have an array with class objects like: Class
Here is a silly question. Lets say I have a query that produces for
This may be a silly question, but right now I have a rather large
This may seem a very silly question. Consider this: I have a simple Boolean
This might be a bit of a silly question but; If I have two

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.