.


:




:

































 

 

 

 


Reflect () string string, , SomeOp.




, C# . . 12, ISeries. (, ISeries , .) , , .

// , using System;

public interface ISeries<T> {

T GetNext();//

void Reset(); // void SetStart(T v); //

}

// ISeries, class ByTwos<T>: ISeries<T> {

T start;

T val;

// , // , public delegate IncByTwo( v);

// ,

// ByTwos.

IncByTwo incr;

public ByTwos(IncByTwo incrMeth) { start = default(T); val = default(T); incr = incrMeth;

}

public T GetNext() { val = incr(val); return val;

}

public void Reset() {

val = start;

}

public void SetStart(T v) { start = v; val = start;

}

}

class ThreeD {

public int x/ , z;

public ThreeD(int a, int b, int c) { x = a;

= b;

z = c;

}

}

class GenlntfDemo {

// // int. static int IntPlusTwo(int v) { return v + 2;

}

// // double, static double DoublePlusTwo(double v) { return v + 2.0;

}

// // ThreeD. static ThreeD ThreeDPlusTwo(ThreeD v) { if(v==null) return new ThreeD(0, 0, 0); else return new ThreeD(v.x + 2, v.y + 2, v.z + 2);

}

static void Main() {

// // int. ByTwos<int> intBT = new ByTwos<int>(IntPlusTwo);

for(int i=0; i < 5; i++)

Console.Write(intBT.GetNext() + " ");

Console.WriteLine();

// // double. ByTwos<double> dblBT =

new ByTwos<double>(DoublePlusTwo); dblBT.SetStart(11.4);

for(int i=0; i < 5; i++)

Console.Write(dblBT.GetNext() + " ");

Console.WriteLine();

// // ThreeD.

ByTwos<ThreeD> ThrDBT = new ByTwos<ThreeD>(ThreeDPlusTwo);

ThreeD coord;

coord.z + " ");

}

Console.WriteLine();

}

}

.

2 4 6 8 10

13.4 15.4 17.4 19.4 21.4 0, 0, 0 2,2,2 4, 4, 4 6, 6, 6 8, 8,8

. ISeries .

public interface ISeries<T> {

, , .

ByTwos, I series.

class ByTwos<T>: ISeries<T> {

ByTwos, ISeries. . , , . , , .

class ByTwos: ISeries<T> { // !

, ISeries, ByTwos. .

, (val) (start), . IncByTwo. , , . ByTwos , - . ByTwos , . incr. , incr.

ThreeD. (X,Z,Y). ByTwos.

Genlntf Demo int, double ThreeD. ByTwos . ThreeDPlusTwo ().

// // ThreeD. static ThreeD ThreeDPlusTwo(ThreeD v) { if(v==null) return new ThreeD(0, 0, 0); else return new ThreeD(v.x + 2, v.y + 2, v.z + 2);

}

, v (null). , ThreeD . , v default () ByTwos. . SetStart(),TO v . , .

, . ISeries .

public interface ISeries<T> where T: class {

ISeries, , .

class ByTwos<T>: ISeries<T> where T: class {

ISeries . , ByTwos<ThreeD>, ByTwos<int> ByTwos<double>.

 

. , Is In (), true, . .

// !

public static bool IsIn<T>(T what, T[] obs) { foreach(T v in obs)

if(v == what) // ! return true;

Return false;

}

, . , , . ? , ? . , .

IComparable IComparable<T> / IEquatable<T>. IComparable (), IEquatable<T> Equals (). IComparable , . IE qua table . System C# , int, string double. . , IEquatable<T>. IEquatable<T> .

public interface IEquatable<T>





:


: 2016-12-03; !; : 429 |


:

:

, ,
==> ...

1510 - | 1491 -


© 2015-2024 lektsii.org - -

: 0.012 .