나는 항상 Equals만 써서 별 생각 없었는데

Mpaper(https://mpaper-blog.tistory.com/)가 IS가 계속 안먹는다고 포럼에 글을 올려보자고 했다.

 

https://forum.uipath.com/t/what-is-the-difference-between-the-two-is-and-equlas/212529

 

What is the difference between the two, "Is" and "Equlas"?

Hi guys! 😄 I have a questions… UiPath has two method “is” and “equals”. But, I don’t know the difference between the two… Example for, var1 = “apple” and there are two codes. condition1 -> var1.equals(“apple”) => Can be run condition2 -> var1 is “apple” =>

forum.uipath.com

 

정리해보자면,

Is

Is 연산자는 두 개체 참조가 동일한 개체를 참조하는지 여부를 확인한다.

그러나 값 비교를 수행하지는 않는다. 비교하는 두 값이 정확히 동일한 개체 인스턴스를 참조하는 경우 True, 그렇지 않으면 False를 수행한다.

Equals

답변해준건 String.Equals 라서 String의 값을 비교할 수 있다고 하는데,

어떤 데이터 타입일지라도 그 값을 가지고서 같은지 비교할 수 있는 것 같다.

즉, 타입과 상관없이 값의 비교를 할 수 있다는 것

 

 

Is 는 참조하는 객체의 메모리 개념이었고

Equals는 값을 비교하는 개념이었다

(결국 is는 참조 객체를 가르키는 주소 값이기 때문에 값 비교가 되지 않는다..)

 


1. Equals에 관련된 .Net 자료

https://docs.microsoft.com/ko-kr/dotnet/api/system.object.equals?view=netframework-4.8

 

Object.Equals 메서드 (System)

 

두 개체 인스턴스가 같은지 확인합니다.Determines whether two object instances are equal.

docs.microsoft.com

2. Is와 관련된 .Net 자료

https://docs.microsoft.com/ko-kr/dotnet/visual-basic/language-reference/operators/is-operator

 

Is 연산자 - Visual Basic

Is 연산자(Visual Basic)Is Operator (Visual Basic) 이 문서의 내용 --> 두 개체 참조 변수를 비교 합니다.Compares two object reference variables. 구문Syntax result = object1 Is object2 요소Parts result 필수입니다.Required. Boolean 값입니다.Any Boolean value. object1 필수입니다.Required. 모든 Object 이름

docs.microsoft.com

 

+ Recent posts