### 技术控

今日:147| 主题:51231

283 6

### 立即注册CoLaBug.com会员，免费获得投稿人的专业资料，享用更多功能，玩转个人品牌！

x
Background:

The Complete list of Operators that can be overloaded are:

• Unary Operator : +,-,!,~,++,–,true,false
• Binary Operator :+,-,*,/,%,&,|,^,<<,>>,==,!=,>,<,>=,<=
The operator which cannot be overloaded

=,&&,||,?:,Cheeked, new, typeof, as, and is operator.
Now we will create Square class. Below is the following codes.

[code]public class Square
{
public decimal Length { set; get; }
public decimal Width { set; get; }

public static Squareoperator *(Square_squareObj1, Square_squareObj2)
{
Square_squareObj = new Square();
_squareObj.Length = _squareObj1.Length * _squareObj2.Length;
_squareObj.Width = _squareObj1.Width * _squareObj2.Width;
return _squareObj;
}

public decimal Area()
{
return Length * Width;
}
}
[/code]  Let’s get explanation about the code:

[code]public class Square
[/code]  Here, square is the class name.

[code]public decimal Length { set; get; }
public decimal Width { set; get; }
[/code]  There are two property of Square Class. One is Length which has decimal data type. And other is width which has decimal type.
[code]        public static Squareoperator *(Square_squareObj1, Square_squareObj2)
{
Square_squareObj = new Square();
_squareObj.Length = _squareObj1.Length * _squareObj2.Length;
_squareObj.Width = _squareObj1.Width * _squareObj2.Width;
return _squareObj;
}
[/code]  The above method implements the Multiplication operator (*) for a user-defined class Square. This method is a static method which have tow parameter. Both are Square’s class objects and both objects done multiplication.
[code]public decimal Area()
{
return Length * Width;
}
[/code]  We have Multiplication Length and Width.
Now we will call Square class in Main function:

[code]class Program
{
static void Main(string[] args)
{
// First Square
Square_obj1 = new Square();
_obj1.Length = 40;
_obj1.Width = 40;

// Second Square
Square_obj2 = new Square();
_obj2.Length = 50;
_obj2.Width = 50;

// For match tow Object
Square_obj3 = new Square();
_obj3 = _obj1 * _obj2;

// Assign area to variable
decimal area = _obj3.Area();
Console.WriteLine(area);

}
}
[/code]  Let’s get explanation about the code:

We have calculated total area of two squares.
[code] Square_obj1 = new Square();
_obj1.Length = 40;
_obj1.Width = 40;
[/code]  We have create object which name given _obje1. We have assigned length of square 40 and  width of square 40
[code]Square_obj2 = new Square();
_obj2.Length = 50;
_obj2.Width = 50;
[/code]  Again, we have create object which name given _obje2. We have assigned length of square 50 and other width of square 50.
[code]Square_obj3 = new Square();
_obj3 = _obj1 * _obj2;
[/code]  New Object have been created for multiplication two object.
[code]decimal area = _obj3.Area();
Console.WriteLine(area);
[/code]  The Area method have been called and assigned result to area variable.

Hope this will be helpful ��

 方力眠n涨姿势了

haining770 发表于 2016-10-2 06:22:43
 锻炼肌肉，防止挨揍！

redak 发表于 2016-10-2 06:53:02
 别回头，哥恋的只是你的背影。

 友情提示：由于此用户的签名太过于个性而被系统自动屏蔽

66644383 发表于 2016-11-7 10:49:53
 撸过。。。。

new5201314 发表于 2016-11-11 13:32:56
 不作死就不会死

• ## 2017支付宝集五福字活动怎么玩?支付宝集福

支付宝集五福活动怎么玩?支付宝集福活动 2017支 [...]

• ## 支付宝扫福集副卡攻略，100%得敬业福

春节即将来临，支付宝推出扫福字活动，据说要把 [...]

• ## 乐视酷派回应前华为员工被抓：不存在泄密行

腾讯科技讯 1月18日，今日有媒体称，华为内 [...]

• ## Mirai botnet creator unmasked as DDOS pr

Mirai, the botnet that subverted thousands [...]

• ## Dispelling the Testimonial Pages are No

In an article on Search Engine Land published [...]

• ## 亲测有效之后 邮政将正式接手无人机邮路的

杭垓镇位于浙江省安吉县西部，全镇辖区面积266.5 [...]

• ## 4 Old-School Characteristics That Make M

The startup landscape is changing, and en [...]

• ## 广告公司，你到底还死不死？

导 读： 不做总统就做广告人，是广告人价 [...]

• ## 网商贷3天无理由退息怎么申请？

网商贷3天无理由退息是什么?“3天无理由退息”是 [...]

• ## 2017支付宝五福卡一天能得几张？支付宝五福

2017支付宝五福卡一天能得几张?支付宝五福集齐攻 [...]

© 2001-2017 Comsenz Inc. Design: Dean. DiscuzFans.