이 예제에서는 같음과 같지 않음에 관한 Point4D 구조체를 테스트하는 방법을 보여 줍니다.
다음 코드는 Point4D 같음 메서드를 사용하여 같음과 같지 않음에 관한 Point4D 구조를 테스트하는 방법을 보여 줍니다. Point4D 구조체는 오버로드된 같음(==
) 연산자를 사용하여 같음에 대해 테스트된 다음 오버로드된 같지 않음(!=
) 연산자를 사용하여 같지 않음에 대해 테스트되고 마지막으로 정적 Equals 메서드를 사용해 Point3D 구조와 Point4D 구조를 같음에 대해 확인합니다.
예시
// instantiate Points
Point4D point4D1 = new Point4D();
Point4D point4D2 = new Point4D(15, 40, 60, 75);
Point3D point3D1 = new Point3D(15, 40, 60);
// result variables
Boolean areEqual;
Boolean areNotEqual;
String stringResult;
// defining x,y,z,w of point1
point4D1.X = 10;
point4D1.Y = 5;
point4D1.Z = 1;
point4D1.W = 4;
// checking if Points are equal
areEqual = point4D1 == point4D2;
// areEqual is False
// checking if Points are not equal
areNotEqual = point4D1 != point4D2;
// areNotEqual is True
if (Point4D.Equals(point4D1, point3D1))
{
// the if condition is not true, so this block will not execute
stringResult = "Both objects are Point4D structures and they are equal";
}
else
{
// the if condition is false, so this branch will execute
stringResult = "Parameters are not both Point4D strucutres, or they are but are not equal";
}
참고하십시오
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET Desktop feedback