C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Operator overloading in C#


Posted Date: 22 Mar 2004    Resource Type: Articles    Category: .NET Framework
Author: Lalitha MaheswaranMember Level: Bronze    
Rating: 1 out of 5Points: 4




using System;

namespace OperatorOverload
{
class Complex
{
int m_nReal;
int m_nImaginary;

public Complex(){}

public Complex(int nReal, int nImg)
{
m_nReal = nReal;
m_nImaginary = nImg;
}

//Note : While overloading the operator use Static keyword :-))
public static Complex operator+ (Complex oComplex1, Complex oComplex2)
{
return new Complex(oComplex1.m_nReal + oComplex2.m_nReal,
oComplex1.m_nImaginary + oComplex2.m_nImaginary);
}


static void Main(string[] args)
{
Complex oComplexA = new Complex(2,4);
Complex oComplexB = new Complex(5,6);

Complex oComplexC = oComplexA + oComplexB;

Console.WriteLine(oComplexC.m_nReal + "i" + oComplexC.m_nImaginary);

}
}
}



Responses

Author: Shaik Abdullah K    02 May 2005Member Level: Silver   Points : 0
Why don't u try to give some explanation about operator over loading?


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Connecting to Database and accessing the records in C#
Previous Resource: GPS Reader NMEA 0-183
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use