TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Operator Overloading In C#
Vijayaragavan S
Aug 24
2016
Code
891
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System;
public
struct
addOpp {
private
double
a;
public
addOpp(
double
a) {
this
.a = a;
}
public
override
string
ToString() {
return
a.ToString();
}
static
public
addOpp
operator
+ (addOpp lhs, addOpp rhs) {
return
new
addOpp(lhs.a + rhs.a);
}
}
class
Operoverload {
static
void
Main(
string
[] args) {
Console.WriteLine(
"Enter Two Numbers"
);
addOpp c1 =
new
addOpp(Convert.ToInt16(Console.ReadLine()));
addOpp c2 =
new
addOpp(
double
.Parse(Console.ReadLine()));
addOpp c3 = c1 + c2;
Console.WriteLine(
"First Value is "
+ c1);
Console.WriteLine(
"Second Value is "
+ c2);
Console.WriteLine(
"Addition is "
+ c3);
Console.ReadKey();
}
}
Operator Overloading
Struct
C#