ارجو منكم اخواني ان تفسرو لي هذه التقنية الجديدة operator و الموجودة في Version 2 .NET و الموجودة في هذا الكود.
public static Cycle operator +(Cycle arg1,int arg2)
{
arg1.Value += arg2;
return arg1;
}
public static Cycle operator -(Cycle arg1, int arg2)
{
arg1.Value -= arg2;
return arg1;
}وأيضا هذا الإستدعاء لهذه التقنية من خلال الكود التالي.
Cycle degrees = new Cycle(0, 359);
Cycle quarters = new Cycle(1, 4);
for (int i = 0; i < 800; i++)
{
degrees += 90;
quarters += 1;
}هذا الكود بشكل كامل , للتوضيح أكثر .
struct Cycle
{
int val, min, max;
Cycle(int min,int max)
{
val = min;
this.min = min;
this.max = max;
}
public int Value
{
get{return val;}
set{if (value > max){
val = min; }
else {if (value < min)
val = max;
else
val = value;}}}
public int ToInteger()
{return Value;}
public override string ToString()
{return Value.ToString();}
public static Cycle operator +(Cycle arg1,int arg2)
{
arg1.Value += arg2;
return arg1;
}
public static Cycle operator -(Cycle arg1, int arg2)
{
arg1.Value -= arg2;
return arg1;
}
static void Main(string[] args)
{
Cycle degrees = new Cycle(0, 359);
Cycle quarters = new Cycle(1, 4);
for (int i = 0; i < 800; i++)
{
degrees += 90;
quarters += 1;
Console.WriteLine("degrees = {0} , quarters = {1}", degrees, quarters);
}
}