174 questions
3
votes
1
answer
502
views
Override Equals method on records
Consider this Minimal Reproducible Example.
Point point1 = new Point(1, 2, 3);
Point point2 = new Point(1, 2, 31);
Console.WriteLine(point1 == point2); // True
Console.WriteLine(point1.Equals(point2)...
0
votes
1
answer
180
views
Weird error message when implementing IEquatable
Class gridTradingState
Implements IEquatable(Of gridTradingState)
Public Overrides Function Equals(other As gridTradingState) As Boolean Implements IEquatable(Of gridTradingState).Equals
...
-1
votes
1
answer
79
views
not printing if both statements are the same
I'm trying to print draw if players and computer choose the same variable, It can not printing if both statements are the same at the moment it just ends after the computers choice and ignores the ...
0
votes
1
answer
719
views
C# comparing int and long as object [duplicate]
If 2 variables of the type "object", which are Int32 and Int64, are compared, "true" is displayed in Visual Studio.
If I save this in a variable, it suddenly changes to "false&...
25
votes
1
answer
21k
views
What is the double question mark equals sign (??=) in C#? [duplicate]
I've been seeing statements like this a lot:
int? a = 5;
//...other code
a ??= 10;
What does the ??= mean in the second line? I've seen ?? used for null coalescing before, but I've never seen it ...
0
votes
3
answers
244
views
Is there a function in Python that does the same thing as the equals operator
Due to my current understanding of Python's syntax, I have run into an issue where I need to set a variable to a value but without using any operators. I have to use functions.
Consider this senario
...
0
votes
0
answers
65
views
Comparing Strings for flight database?
My task was to create a list of flights using ArrayList. I've created a Main class, a Flight class and FlightDatabase class,and in FlightDatabase I've added a few new Flights with departure and array ...
4
votes
2
answers
365
views
"ulong == ulong?" evaluated as "ulong == ulong" works correctly
If we use the == operator between an expression of ulong and an expression of ulong?, then the operator overload bool ulong(ulong left, ulong right) appears to be used.
In other words, the operator ...
-5
votes
2
answers
250
views
What does an OBJECT EQUALS method do internally? How to know the value stored in an Object eg: Object_Comparison? [duplicate]
I know that .equals methods from the Object class in Java compares the content of the object but what does it do in the below code and why is it FALSE as i put in the comment line? Please let me know.
...
22
votes
2
answers
2k
views
Does == actually work the same or different when comparing two primitives vs two Objects in Java?
When searching for explanations of how logical equals == works in Java the answers are always something along the lines of:
For primitives it returns whether the primitives have the same value (this ...
1
vote
0
answers
44
views
equals() method and object comparing [duplicate]
I was studying basics of java and saw equals() method and wrote this code
public class EqualsTest {
public static void main(String[] args) {
String str = new String("this");
String str2 = new ...
3
votes
1
answer
70
views
In javascript tripple equals, what is checked first? type or value?
If I try to compare two objects in javascript using triple equals,
object1 === object2
It checked both, type and value.
My question is, which one is tested first? type or value?
7
votes
2
answers
220
views
Why does commuting the arguments of == in a console change the output?
If I open my browser console (tested in Chrome/Firefox) and type:
null == {}
I get:
false
However, if I commute both arguments to the == operator and instead type:
{} == null
I get:
Uncaught ...
0
votes
0
answers
56
views
Side effects of breaking the relation between __eq__ and __hash__ in Python 3
According to the Python 3 documentation, objects that compare equal should have the same hash value. However, it is not uncommon to have two different mutable objects that at a given time can be ...
0
votes
3
answers
300
views
Should i use array_diff_assoc or ===?
I'm trying to compare two arrays to see if they are sorted or not.
What is the difference between array_diff_assoc and comparing two arrays with the === operator?
Are they the same thing?
For example
...
0
votes
1
answer
55
views
'and', 'or' for python unequal statement between strings
I am reading a text file using python. Each line will be read if the first character does not equal to # or @. The content of the text is pasted in the end.
This works:
if line[0] != '#' and line[0] ...
1
vote
1
answer
262
views
Numpy equal to not working properly
I have a dataframe with values new_df.values
arr = np.array([[ 0. , 0.31652875, 0.05650486, 0.11726623, 0.30987541,
0.30987541, 0.30987541],
[ 0.31652875, 0. , 0.34982559,...
-1
votes
1
answer
139
views
Code errors at no operator overload
I've got a class using an std::vector> to indicate the item and its count (there can be multiple inventoryitems containing the same item).
I then proceeded to overload the clsInventoryItem its == ...
0
votes
2
answers
903
views
What are the restrictions in comparing two pointers?
int a=40,b=34;
int *iptr1,*iptr2;
iptr1 = &a;
iptr2 = &b;
printf("\n Equal condition of two pointers=%d", (ip1 == ip2)); //no error
char name1[20], name2[...
2
votes
2
answers
4k
views
Java 8, equals, == and Lambdas
(actual question at the end)
Hello World!
I've got some disturbing thing happening here that I cannot wrap my head around...
Laszy as I am, I hate re-implementing the stupid euqals() emthods over ...
0
votes
2
answers
755
views
Why does an assignment in an if statement equate to true?
Let me start off by saying I understand the difference between =, ==, and
===. The first is used to assign the right-hand value to the left-hand variable, the second is used to compare the ...
0
votes
5
answers
110
views
Equal (==) and equal (===) not working for me
I am using if condition in jquery and == is not working for me nor === . :(
Here is my code:
var hash = window.location.hash;
var hash = hash.replace('#', ' ');
alert(hash); /* Returns abc.*/
if( ...
1
vote
1
answer
38
views
Why is Equals called after method has resolved?
I don't know what is calling my Equals method, because when the breakpoint is hit there is no call stack (except the Equals itself and [External Code]).
I have a class UserComplete that has methods ...
0
votes
0
answers
28
views
Generic Equality Comparer [duplicate]
I am trying to write a generic equality comparer. I've written the following code.
public static bool Equals<T>(T t1, T t2)
{
bool result;
if (typeof(T).IsPrimitive)
{
...
0
votes
0
answers
23
views
Two similar arrays produce falsity with == comparision? [duplicate]
Lets take two arrays
var apple = [1,2,3];
var bracket = [1,2,3];
and a string cat here with the same contents as the initial 2 arrays with no difference except comma (,)
var cat = "1,2,3";
Now lets ...