BNF Question

Xinok xnknet at gmail.com
Sun Sep 2 22:09:55 PDT 2007


An equal expression is when the data in two objects is compared.
int[] arr1 = [10, 20, 30], arr2 = [10, 20, 30];
if(arr1 == arr2){ } // True

An identity expresion is when the pointer values (and .length in arrays) 
in two objects is compared.
int[] arr1 = [10, 20, 30], arr2 = arr1;
if(arr1 is arr2){ } // True

For primitive types, there is no difference between using == and is.
int a = 15, b = 15;
if(a == b){ } // True
if(a is b){ } // True

BCS wrote:
> What is the difference between an Identity Expression and a Equal 
> Expression? both have a "ShiftExpression is ShiftExpression" and a 
> "ShiftExpression !is ShiftExpressionand".
> 
> http://www.digitalmars.com/d/expression.html#EqualExpression
> http://www.digitalmars.com/d/expression.html#IdentityExpression
> 
> 


More information about the Digitalmars-d-learn mailing list