<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FOperator_Overload%2Foperator_overload_Binary_Plus_Subtract</id>
		<title>Csharp/CSharp Tutorial/Operator Overload/operator overload Binary Plus Subtract - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FOperator_Overload%2Foperator_overload_Binary_Plus_Subtract"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Operator_Overload/operator_overload_Binary_Plus_Subtract&amp;action=history"/>
		<updated>2026-04-30T03:19:41Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Operator_Overload/operator_overload_Binary_Plus_Subtract&amp;diff=6400&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Operator_Overload/operator_overload_Binary_Plus_Subtract&amp;diff=6400&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Operator_Overload/operator_overload_Binary_Plus_Subtract&amp;diff=6401&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Operator_Overload/operator_overload_Binary_Plus_Subtract&amp;diff=6401&amp;oldid=prev"/>
				<updated>2010-05-26T12:18:55Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Add + operator for Complex type==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
public struct Complex&lt;br /&gt;
{&lt;br /&gt;
    public Complex( double real, double imaginary ) {&lt;br /&gt;
        this.real = real;&lt;br /&gt;
        this.imaginary = imaginary;&lt;br /&gt;
    }&lt;br /&gt;
    static public Complex Add( Complex lhs, Complex rhs ) {&lt;br /&gt;
        return new Complex( lhs.real + rhs.real, lhs.imaginary  + rhs.imaginary );&lt;br /&gt;
    }&lt;br /&gt;
    static public Complex Add( Complex lhs, double rhs ) {&lt;br /&gt;
        return new Complex( rhs + lhs.real, lhs.imaginary );&lt;br /&gt;
    }&lt;br /&gt;
    public override string ToString() {&lt;br /&gt;
        return String.Format( &amp;quot;({0}, {1})&amp;quot;, real, imaginary );&lt;br /&gt;
    }&lt;br /&gt;
    static public Complex operator+( Complex lhs, Complex rhs ) {&lt;br /&gt;
        return Add( lhs, rhs );&lt;br /&gt;
    }&lt;br /&gt;
    static public Complex operator+( double lhs, Complex rhs ) {&lt;br /&gt;
        return Add( rhs, lhs );&lt;br /&gt;
    }&lt;br /&gt;
    static public Complex operator+( Complex lhs, double rhs ) {&lt;br /&gt;
        return Add( lhs, rhs );&lt;br /&gt;
    }&lt;br /&gt;
    private double real;&lt;br /&gt;
    private double imaginary;&lt;br /&gt;
}&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Complex cpx1 = new Complex( 1.0, 3.0 );&lt;br /&gt;
        Complex cpx2 = new Complex( 1.0, 2.0 );&lt;br /&gt;
        Complex cpx3 = cpx1 + cpx2;&lt;br /&gt;
        Complex cpx4 = 20.0 + cpx1;&lt;br /&gt;
        Complex cpx5 = cpx1 + 25.0;&lt;br /&gt;
        Console.WriteLine( &amp;quot;cpx1 == {0}&amp;quot;, cpx1 );&lt;br /&gt;
        Console.WriteLine( &amp;quot;cpx2 == {0}&amp;quot;, cpx2 );&lt;br /&gt;
        Console.WriteLine( &amp;quot;cpx3 == {0}&amp;quot;, cpx3 );&lt;br /&gt;
        Console.WriteLine( &amp;quot;cpx4 == {0}&amp;quot;, cpx4 );&lt;br /&gt;
        Console.WriteLine( &amp;quot;cpx5 == {0}&amp;quot;, cpx5 );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;cpx1 == (1, 3)&lt;br /&gt;
cpx2 == (1, 2)&lt;br /&gt;
cpx3 == (2, 5)&lt;br /&gt;
cpx4 == (21, 3)&lt;br /&gt;
cpx5 == (26, 3)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==An operator overloading: binary + and -==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System; &lt;br /&gt;
 &lt;br /&gt;
class TwoDimension { &lt;br /&gt;
  int x, y;   &lt;br /&gt;
 &lt;br /&gt;
  public TwoDimension() { &lt;br /&gt;
     x = y = 0; &lt;br /&gt;
  } &lt;br /&gt;
  public TwoDimension(int i, int j) { &lt;br /&gt;
     x = i; &lt;br /&gt;
     y = j;  &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Overload binary +. &lt;br /&gt;
  public static TwoDimension operator +(TwoDimension op1, TwoDimension op2) &lt;br /&gt;
  { &lt;br /&gt;
    TwoDimension result = new TwoDimension(); &lt;br /&gt;
 &lt;br /&gt;
    result.x = op1.x + op2.x; &lt;br /&gt;
    result.y = op1.y + op2.y; &lt;br /&gt;
 &lt;br /&gt;
    return result; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Overload binary -. &lt;br /&gt;
  public static TwoDimension operator -(TwoDimension op1, TwoDimension op2) &lt;br /&gt;
  { &lt;br /&gt;
    TwoDimension result = new TwoDimension(); &lt;br /&gt;
 &lt;br /&gt;
    /* Notice the order of the operands. op1 is the left &lt;br /&gt;
       operand and op2 is the right. */ &lt;br /&gt;
    result.x = op1.x - op2.x;&lt;br /&gt;
    result.y = op1.y - op2.y;  &lt;br /&gt;
 &lt;br /&gt;
    return result; &lt;br /&gt;
  } &lt;br /&gt;
   &lt;br /&gt;
  public void show() &lt;br /&gt;
  { &lt;br /&gt;
    Console.WriteLine(x + &amp;quot;, &amp;quot; + y); &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
class MainClass { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    TwoDimension a = new TwoDimension(1, 2); &lt;br /&gt;
    TwoDimension b = new TwoDimension(10, 10); &lt;br /&gt;
    TwoDimension c = new TwoDimension(); &lt;br /&gt;
 &lt;br /&gt;
    Console.Write(&amp;quot;Here is a: &amp;quot;); &lt;br /&gt;
    a.show(); &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
    Console.Write(&amp;quot;Here is b: &amp;quot;); &lt;br /&gt;
    b.show(); &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    c = a + b; // add a and b together &lt;br /&gt;
    Console.Write(&amp;quot;Result of a + b: &amp;quot;); &lt;br /&gt;
    c.show(); &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    c = a + b + c; // add a, b and c together &lt;br /&gt;
    Console.Write(&amp;quot;Result of a + b + c: &amp;quot;); &lt;br /&gt;
    c.show(); &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    c = c - a; // subtract a &lt;br /&gt;
    Console.Write(&amp;quot;Result of c - a: &amp;quot;); &lt;br /&gt;
    c.show(); &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
 &lt;br /&gt;
    c = c - b; // subtract b &lt;br /&gt;
    Console.Write(&amp;quot;Result of c - b: &amp;quot;); &lt;br /&gt;
    c.show(); &lt;br /&gt;
    Console.WriteLine(); &lt;br /&gt;
  } &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Here is a: 1, 2&lt;br /&gt;
Here is b: 10, 10&lt;br /&gt;
Result of a + b: 11, 12&lt;br /&gt;
Result of a + b + c: 22, 24&lt;br /&gt;
Result of c - a: 21, 22&lt;br /&gt;
Result of c - b: 11, 12&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Operator overloading: +, -==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
public class Point&lt;br /&gt;
{&lt;br /&gt;
    public Point( int x, int y )&lt;br /&gt;
    {&lt;br /&gt;
        this.X = x;&lt;br /&gt;
        this.Y = y;&lt;br /&gt;
    }&lt;br /&gt;
    public int X;&lt;br /&gt;
    public int Y;&lt;br /&gt;
    public static Point operator + ( Point a, Point b )&lt;br /&gt;
    {&lt;br /&gt;
        return new Point( a.X + b.X, a.Y + b.Y );&lt;br /&gt;
    }&lt;br /&gt;
    public static Point operator - ( Point a )&lt;br /&gt;
    {&lt;br /&gt;
        return new Point( - a.X , - a.Y );&lt;br /&gt;
    }&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        Point p = new Point( 3, 4 );&lt;br /&gt;
        Point q = new Point( 36, -5 );&lt;br /&gt;
        Point r = p + ( - q );&lt;br /&gt;
        System.Console.WriteLine( &amp;quot;Result: x = {0}, y = {1}&amp;quot;, r.X, r.Y );&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Result: x = -33, y = 9&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>