473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Are these objects equal?

Hi, i want to compare two objects. i wrote the program as bellow,
........................
namespace TestPrograms
{
class test
{
public int i;
}
class Exercise
{
public static void Main(string[] s)
{
test t1=new test();
test t2=new test();

t2.i=10;
t1.i=10;

if(t1.Equals(t2))
{
Console.WriteLine("Eql");
}
else
{
Console.WriteLine("NotEql");
}
}
}

}
....................
O/P is "NotEql"
..................
my question is ,
why t1 and t2 are not equal?
when two objects are said to be equal?
Aug 18 '07 #1
1 1074
Assam
4
Object.Equal method is a virtual method. So if you call the base class method it will compare the references of both objects(i.e. both objects referring to same memory location).
You can override this method in your class to give your own functionality. One possible reason could be to compare the state of both objects as you require.
If this is not helpful let me know i will provide the sample code.
Aug 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: mihai | last post by:
How can I build a set of unordered objects lets say POINT_2D objects? The POINT_2D class does not have a consistent operator<. Have a nice day, Mihai.
115
by: junky_fellow | last post by:
What is a C object ? If i have some function "func()" in my C program, then can i say that "func()" is a C object ? or if i have some function pointer (ptr) which contains the address of...
4
by: emagutu | last post by:
Hi, I have been geiven the following Task. Class, inheritance, polymorphism, file handling, arrays or linked list. A C++ program is required to handle three types of objects: - Trucks - Cars...
7
by: Jay Douglas | last post by:
In C# 2.0 I need to compare instances of an object to see if they are equal based on an id property. The object properties are class Cat { int CatId; string CatName; }
7
by: Prabhudhas Peter | last post by:
I have two object instances of a same class... and i assigned values in both object instances (or the values can be taken from databse and assigned to the members of the objects)... Now i want to...
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
5
by: Yves Glodt | last post by:
Hello, I need to compare 2 instances of objects to see whether they are equal or not, but with the code down it does not work (it outputs "not equal") #!/usr/bin/python class Test:
6
by: Martin | last post by:
Hi I need to maintain a <setof pointers to objects, and it must be sorted based on the values of pointed objects, not pointer values. I can achieve this easily by defining my own comparing...
5
by: davenet | last post by:
Hi, I'm new to Python and working on a school assignment. I have setup a dictionary where the keys point to an object. Each object has two member variables. I need to find the smallest value...
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.