.


:




:

































 

 

 

 


, MyMeth () IMylF , .




. -, , , , . , , , . -, , . . .

IEven, : IsEven () IsOdd (). , . IEven MyClass. IsOdd () .

// , using System;

interface IEven { bool IsOdd(int x); bool IsEven(int x);

}

class MyClass: IEven {

// . , // , bool IEven.IsOdd(int x) { if((x%2)!= 0) return true;

Else return false;

}

// , public bool IsEven(int x) {

IEven = this; // , return!.IsOdd();

}

}

class Demo {

static void Main() {

MyClass ob = new MyClass(); bool result;

result = ob.IsEven (4);

if(result) Console.WriteLine("4 .");

// result = ob.IsOdd(4); // , IsOdd IEven

// , // IEven MyClass, // IsOdd().

IEven iRef = (IEven) ob; result = iRef.IsOdd(3);

if(result) Console.WriteLine("3 .");

}

}

IsOdd () , , MyClass. , . IEven IsEven ().

, , Meth (). , .

interface IMyIF_A { int Meth(int x);

}

interface IMyIF_B { int Meth(int x);

}

// MyClass. class MyClass: IMyIF_A, IMyIF_B {

// Meth() , int IMyIF_A.Meth(int x) { return x + x;

}

int IMyIF_B.Meth(int x) { return x * x;

}

// Meth() . public int MethA(int x){

IMyIF_A a_ob; a_ob = this;

return a_ob.Meth(x); // IMyIF_A

}

public int MethB(int x){

IMyIF_B b_ob; b_ob = this;

return b_ob.Meth(x); // IMyIF_B

}

}

class FQIFNames {

static void Main() {

MyClass ob = new MyClassO;

Console.Write(" IMyIF_A.Meth(): ");

Console.WriteLine(ob.MethA(3));

Console.Write(" IMyIF_B.Meth(): ");

Console.WriteLine(ob.MethB(3));

}

}

.

IMyIF_A.Meth(): 6 IMyIF_B.Meth(): 9

, Meth () , IMyIF_A IMyIF_B. MyClass, , .. Meth ().

, MyClass : IMyIF_A, IMyIF_B. , .

C# , , . : - , , . , .

.NET Framework

.NET Framework , #. , System. IComparable CompareTo (), , . , , , . , System. Collections. ICollection , System.Collections. IEnumerator . II .

, . , , , . , , . ( ) . C# , , , .

struct . :

struct : {

II

}

.

. (, , #, obj ect.) , . , : , , , , . , . , (.. ). , , , . , . , abstract, virtual protected.

new , , . new, , . , - , . .





:


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


:

:

. .
==> ...

1736 - | 1660 -


© 2015-2024 lektsii.org - -

: 0.027 .