SlideShare a Scribd company logo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OperatorOverloading_0086
{
class Point
{
public int X, Y;
internal static double Distance(Point p1, Point p2)
{
return Math.Sqrt((p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) *
(p2.Y - p1.Y)); //(x2- x1)*(x2- x1)+(y2- y1)*(y2- y1)
}
public static double operator - (Point p1, Point p2)
{
return Math.Sqrt((p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) *
(p2.Y - p1.Y));
}
public static bool operator >(Point p1, Point p2)
{
return p1.X > p2.X && p1.Y > p2.Y;
}
public static bool operator <(Point p1, Point p2)
{
return p1.X < p2.X && p1.Y < p2.Y;
}
}
class Program
{
static void Main(string[] args)
{
Point p1 = new Point() { X = 1, Y = 2 };
Point p2 = new Point() { X = 3, Y = 4 };
double distance;
distance = Point.Distance(p1, p2);
distance = p2-p1;
Console.WriteLine(distance);
if (p1 > p2)
Console.WriteLine("P1 is greater.");
else
Console.WriteLine("P2 is greater.");
}
}
}

More Related Content

TXT
DOCX
Jarmo van de Seijp Shadbox ERC223
PPTX
JVM Architecture - Java
TXT
123
ODP
Pick up the low-hanging concurrency fruit
PDF
GPars howto - when to use which concurrency abstraction
DOCX
WAP to add two given matrices in Java
PDF
Reactive x
Jarmo van de Seijp Shadbox ERC223
JVM Architecture - Java
123
Pick up the low-hanging concurrency fruit
GPars howto - when to use which concurrency abstraction
WAP to add two given matrices in Java
Reactive x

What's hot (20)

PPTX
Queue Implementation Using Array & Linked List
ODP
Concurrency on the JVM
PPT
Algo>Queues
PDF
PPT
Link list part 2
PPTX
multiple linear regression
ODP
Functors, applicatives, monads
DOCX
PPT
Doublylinklist
PPTX
LINKED LISTS
DOCX
Fisica ii codigo
PPTX
20170714 concurrency in julia
PDF
Pivorak Clojure by Dmytro Bignyak
PPTX
simple linear regression
PPTX
decision tree regression
PPT
Standard Template Library (STL) in Object Oriented Programming
PDF
Recursion concepts by Divya
PDF
Леонид Шевцов «Clojure в деле»
PDF
Меняем javascript с помощью javascript
PDF
Ns2: Introduction - Part I
Queue Implementation Using Array & Linked List
Concurrency on the JVM
Algo>Queues
Link list part 2
multiple linear regression
Functors, applicatives, monads
Doublylinklist
LINKED LISTS
Fisica ii codigo
20170714 concurrency in julia
Pivorak Clojure by Dmytro Bignyak
simple linear regression
decision tree regression
Standard Template Library (STL) in Object Oriented Programming
Recursion concepts by Divya
Леонид Шевцов «Clojure в деле»
Меняем javascript с помощью javascript
Ns2: Introduction - Part I
Ad

Similar to Operator overloading (binary) (20)

PDF
Les nouveautés de C# 6
PPTX
Chapter 7 functions (c)
PDF
Point.javapublic class Point {    int x,y;    double m,n; .pdf
PDF
code#includeiostream using namespace std; class Point {.pdf
PDF
Java 8 lambda expressions
PPTX
Monadic Comprehensions and Functional Composition with Query Expressions
PDF
Kotlin Bytecode Generation and Runtime Performance
PDF
"Java Concurrency Stress tests Tool" at IT Tage 2017 by Vadym Kazulkin/Rodion...
PDF
6. function
PDF
Points.java import java.util.ArrayList; import java.util.Scan.pdf
PPT
Inheritance and-polymorphism
PDF
Hi,I have modified the Point.java file as per your requirement.P.pdf
PPS
Class method
DOCX
PRACTICAL COMPUTING
PDF
TypeScript Introduction
PDF
Java 8 - Nuts and Bold - SFEIR Benelux
DOCX
java assignment
PDF
import java.util.Scanner;public class Factorial { method usi.pdf
PPTX
Design pattern - part 3
Les nouveautés de C# 6
Chapter 7 functions (c)
Point.javapublic class Point {    int x,y;    double m,n; .pdf
code#includeiostream using namespace std; class Point {.pdf
Java 8 lambda expressions
Monadic Comprehensions and Functional Composition with Query Expressions
Kotlin Bytecode Generation and Runtime Performance
"Java Concurrency Stress tests Tool" at IT Tage 2017 by Vadym Kazulkin/Rodion...
6. function
Points.java import java.util.ArrayList; import java.util.Scan.pdf
Inheritance and-polymorphism
Hi,I have modified the Point.java file as per your requirement.P.pdf
Class method
PRACTICAL COMPUTING
TypeScript Introduction
Java 8 - Nuts and Bold - SFEIR Benelux
java assignment
import java.util.Scanner;public class Factorial { method usi.pdf
Design pattern - part 3
Ad

Recently uploaded (20)

PPTX
Learning-Plan-5-Policies-and-Practices.pptx
PPTX
Introduction to Effective Communication.pptx
PPTX
Cohort Study_PPT.group presentation_pdf.pptx
PPTX
Self management and self evaluation presentation
PPTX
Caption Text about Social Media Post in Internet
PPTX
What is Clause, definition and structure
PDF
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
PPTX
Role and Responsibilities of Bangladesh Coast Guard Base, Mongla Challenges
PDF
SweeneyS-InclusiveLanguage-WeekOne (1).pdf
PPTX
Presentation of Project of Enterprenuership topic- "Green Gaurdian"
PPTX
business communication final draftt.pptx
PPTX
Emphasizing It's Not The End 08 06 2025.pptx
PDF
Instagram's Product Secrets Unveiled with this PPT
PPTX
Non-Verbal-Communication .mh.pdf_110245_compressed.pptx
PPTX
2025-08-03 Joseph 01 (shared slides).pptx
PPTX
Presentation for DGJV QMS (PQP)_12.03.2025.pptx
PPTX
IBA DISTRICT PIR PRESENTATION.POWERPOINT
PPTX
Phrase, structure, use, definition in sentence
PPTX
Called To More (Final I Think) 08 03 2025.pptx
PPTX
Understanding-Communication-Berlos-S-M-C-R-Model.pptx
Learning-Plan-5-Policies-and-Practices.pptx
Introduction to Effective Communication.pptx
Cohort Study_PPT.group presentation_pdf.pptx
Self management and self evaluation presentation
Caption Text about Social Media Post in Internet
What is Clause, definition and structure
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
Role and Responsibilities of Bangladesh Coast Guard Base, Mongla Challenges
SweeneyS-InclusiveLanguage-WeekOne (1).pdf
Presentation of Project of Enterprenuership topic- "Green Gaurdian"
business communication final draftt.pptx
Emphasizing It's Not The End 08 06 2025.pptx
Instagram's Product Secrets Unveiled with this PPT
Non-Verbal-Communication .mh.pdf_110245_compressed.pptx
2025-08-03 Joseph 01 (shared slides).pptx
Presentation for DGJV QMS (PQP)_12.03.2025.pptx
IBA DISTRICT PIR PRESENTATION.POWERPOINT
Phrase, structure, use, definition in sentence
Called To More (Final I Think) 08 03 2025.pptx
Understanding-Communication-Berlos-S-M-C-R-Model.pptx

Operator overloading (binary)

  • 1. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OperatorOverloading_0086 { class Point { public int X, Y; internal static double Distance(Point p1, Point p2) { return Math.Sqrt((p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) * (p2.Y - p1.Y)); //(x2- x1)*(x2- x1)+(y2- y1)*(y2- y1) } public static double operator - (Point p1, Point p2) { return Math.Sqrt((p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) * (p2.Y - p1.Y)); } public static bool operator >(Point p1, Point p2) { return p1.X > p2.X && p1.Y > p2.Y; } public static bool operator <(Point p1, Point p2) { return p1.X < p2.X && p1.Y < p2.Y; } } class Program { static void Main(string[] args) { Point p1 = new Point() { X = 1, Y = 2 }; Point p2 = new Point() { X = 3, Y = 4 }; double distance; distance = Point.Distance(p1, p2); distance = p2-p1; Console.WriteLine(distance); if (p1 > p2) Console.WriteLine("P1 is greater."); else Console.WriteLine("P2 is greater."); } } }