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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:35:04+00:00 2026-06-14T02:35:04+00:00

Given two object arrays I need to compare the differences between the two (when

  • 0

Given two object arrays I need to compare the differences between the two (when converted to a string). I’ve reduced the code to the following and the problem still exists:

public void Compare(object[] array1, object[] array2) {
    for (var i = 0; i < array1.Length; i++) {
        var value1 = GetStringValue(array1[i]);
        var value2 = GetStringValue(array2[i]);
    }
}

public string GetStringValue(object value) {
    return value != null && value.ToString() != string.Empty ?
        value.ToString() : "No Value";
}

The code executes fine no matter what object arrays I throw at it. However if one of the items in the array is a reference type then somehow the reference is updated. This causes issues later.

It appears that this happens when calling ToString() against the object reference. I have updated the GetStringValue method to the following (which makes sure the object is either a value type or string) and the problem goes away.

public string GetStringValue(object value) {
    return value != null && (value.GetType().IsValueType || value is string)
        && value.ToString() != string.Empty ? value.ToString() : "No Value";
}

However this is just a temporary hack as I’d like to be able to override the ToString() method on my reference types and compare them as well.

I’d appreciate it if someone could explain why this is happening and offer a potential solution. Thanks

Edit:

To help further explain my application. This piece of code is taken from an NHibernate event listener. I think the problem lies from NHibernate adding it’s own wrapper around a class to deal with lazy loading. Here’s the error it throws:

collection [*] was not processed by flush()

  • 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-14T02:35:06+00:00Added an answer on June 14, 2026 at 2:35 am

    It sounds like there may well be a side effect going on within the ToString() method for the reference type, which is generally bad practise as this is a method often used by the .NET framework.

    For this to be the case the following would have to be true:

    • You are using a custom class that yourself or another 3rd Party built.
    • Some modification of the object occurs when calling ToString().

    To verify this you could just create an instance of the reference type and call ToString() on it. See if the object has changed (GetHashCode() may be one way to determine this). Or you could inspect the code…

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

Sidebar

Related Questions

Given two strings text1 and text2 : public SOMEUSABLERETURNTYPE Compare(string text1, string text2) {
in my code, I need to compare two strings to see if they are
Given the following two objects: function newDoodle() { var Doodle = { /* Variables
Given I have two File objects I can think of the following implementation: public
Given two tuples of the same arity, how can I lexicographically compare them? It
Given two arrays, how to find the maximum element which is common to both
Given two sorted arrays of integers, a and b , and an integer c
I want to create an Object that contains one or more two dimensional arrays
Given two Date() objects, where one is less than the other, how do I
Given two stream-oriented I/O objects in Asio , what is the simplest way to

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.