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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:41:22+00:00 2026-06-02T06:41:22+00:00

I am trying to compare two Lists using CollectionAssert.AreEqual(ListExpected, ListActual); But I am getting

  • 0

I am trying to compare two Lists using

 CollectionAssert.AreEqual(ListExpected, ListActual);

But I am getting an exception

Expected and actual are both <System.Collections.Generic.List`1[API.Program.Relation]> with 11 elements
  Values differ at index [0]
  Expected: <API.Program.Relation>
  But was:  <API.Program.Relation>

But when I compared the zero element using Assert.AreEqual on field by field everything was fine.

Any idea why I cannot compare using CollectionAssert

  • 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-02T06:41:25+00:00Added an answer on June 2, 2026 at 6:41 am

    An object is “declared” equal to another object in .NET is if its Equals(object other) method returns true. You need to implement that method for your API.Program.Relation class, otherwise .NET considers your objects different unless they are reference-equal. The fact that all fields are the same does not matter to .NET: if you need field-by-field equality semantics, you need to provide an implementation of Equals that supports it.

    When you override Equals, don’t forget to override GetHashCode as well – these must be overriden together.

    If you do not want to or cannot override Equals for some reason, you could use an overload of CollectionAssert.AreEqual that takes an instance of IComparer to assist in comparing collection elements.

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

Sidebar

Related Questions

I am trying to compare two lists of data which has some free text
I am trying to compare two strings in Smalltalk, but I seem to be
I'm trying to compare two datetimes but I can't get it to work. public
I am trying to compare two lists of string in python. Some of the
I am trying to Compare two lists and keep on each list only items
I'm trying to write a function in three classes that will compare two lists
I have two lists that I am trying to compare with < or >
I'm trying to compare two lists by length and set the output to true
I am trying to compare two files. I will list the two file content:
I'm trying to implement a custom comparer on two lists of strings and use

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.