Click here to Skip to main content
15,910,886 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
which one is faster, "compare" or "=="
Posted
Updated 7-Feb-10 9:17am
v3

You seem to be asking a lot of vague and general questions. If you're doing a course, sit back and follow the structure of your course. If you're teaching yourself, then you should buy a book and work through that. In this case, the short answer is, it's hard to think of many applications where the speed of the == operator is likely to be a bottleneck to performance. Don't worry too much about such things, until you find yourself in a place where they matter, because they rarely do. Computers are fast nowadays.

Just to add, you should try to expand on your question and explain why you're asking it in the body of your post, don't just repeat the subject line.
 
Share this answer
 
v2
If you understand the functionality of each of the two methods you mentioned you will know that each one has its own work, both some how give you the same result eventually, but for instance the == operator is used with value type to tell if they have the same value or not, and for reference types it returns whether the operands refer to the same object or not (except for string where its treated like value type in this case).

Mostly you will need to use the compare function with a custom comparer that will do some kind of business compare or something.

For performance, I am not pretty sure of that, but using the equality operator is faster as I think if its sufficient for your needs.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900