, <Func<int, int, boo 1> . Fun int bool. Fun , -, . - Fun . , Fun -.
, , . , , , . , , . LINQ.
, . , . , this. , , . . , , , - , , .
.
static _ (this __ ob, _)
, _ , , . , , , , . , .
.
// , using System;
using System.Globalization; static class MyExtMeths {
// double, public static double Reciprocal(this double v) { return 1.0 / v;
}
// // , public static string RevCase(this string str) { string temp =
foreach(char ch in str) {
if(Char.IsLower(ch)) temp += Char.ToUpper (ch, Culturelnfo.
CurrentCulture);
else temp += Char.ToLower(ch, Culturelnfo.CurrentCulture);
}
Return temp;
}
// n / d. public static double AbsDivideBy(this double n, double d) { return Math.Abs(n / d);
}
}
class ExtDemo {
static void Main() {
double val = 8.0;
string str = "Alpha Beta Gamma";
|
|
// Reciprocal()..
Console.WriteLine(" {0} {1}", val, val.Reciprocal());
// RevCaseO.
Console.WriteLine(str + " : " + str.RevCase ());
// AbsDivideBy().
Console.WriteLine(" val.AbsDivideBy(-2): " + val.AbsDivideBy(-2));
}
}
8 0.125
Alpha Beta Gamma : aLPHA val.AbsDivideBy(-2): 4
MyExtMeths. , . , , . ( System. Linq, , LINQ.)
, . , .
Val.AbsDivideBy(-2)