.


:




:

































 

 

 

 


?




5. ?

6. ?

7. ?

8. ?

9. ?

10. ?

11. protected private?

:

1. 1-4. .

2. , 10 . , .

3. , . - , , , .

4. , , , . 2 3 . , . . . .

5. , , . , , , . . . .

6. , 10, , . . . . . () .

7. , , , , . , . , , , . . . () .

8. , , , . ( ). , . readonly . . . . , .

9. , , , . ( ). , . readonly . . . . , .

10. , , . ( ). , . . readonly . . . . , .

11. , , . ( ). , . . readonly . . . . , .

12. , 10, . . . . .

13. , , . ( ). , , . . readonly . . . . ,

 

 

4

 

- , .

, .

. , .

, System.Delegate. .

. , .

, :

 

static int min(int x,int y),

 

, :

 

delegate int LpFunc(int a,int b);

 

:

 

LpFunc pfnk = new LpFunk(CA.min);

, , .

 

1:

using System;

namespace ConsoleApplication14

{

class MathOprt

{

public static double Mul2(double val)

{

return val*2;

}

public static double Sqr(double val)

{

return val*val;

}

}

delegate double DblOp(double x); //

class Class1

{

static void Main(string[] args)

{

DblOp [] operation = //

{

new DblOp(MathOprt.Mul2),

new DblOp(MathOprt.Sqr)

};

for(int j=0;j<operation.Length;j++)

{

Console.WriteLine(" [{0}]:",j);

Prc(operation[j], 4.0);

Prc(operation[j], 9.94);

Prc(operation[j], 3.143);

}

}

static void Prc(DblOp act, double val)

{

double rslt = act(val);

Console.WriteLine(" {0}, {1}",

val,rslt);

}

}

}

. . , . .

, + = . , - = .

, void.

1 .

 

2:

 

using System;

namespace ConsoleApplication14

{

class MathOprt

{

public static void Mul2(double val)

{

double rslt= val*2;

Console.WriteLine("Mul2 b {0}, {1}",

val,rslt);

}

public static void Sqr(double val)

{

double rslt = val*val;

Console.WriteLine("Sqr {0}, {1}",

val,rslt);

}

}

delegate void DblOp(double x);//

 

class Class1

{

[STAThread]

static void Main(string[] args)

{

DblOp operations = new DblOp(MathOprt.Mul2);

operations += new DblOp(MathOprt.Sqr);

Prc(operations, 4.0);

Prc(operations, 9.94);

Prc(operations, 3.143);

}

static void Prc(DblOp act, double val)

{

Console.WriteLine("\n*********\n");

act(val);

}

}

}

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

.NET :

void OnRecChange(object source, ChangeEventArgs e)

{

//

}

 

void. . _ , . . EventArgs . .

. :

 

public delegate void ChangeEventHandle(object source,ChangeEventArgs e);

 

, event , , :

 

public event ChangeEventHandler OnChangeHandler;

 

. +=, :

gnEvent.OnChangeHandler +=

new GenEvent.ChangeEventHandler (OnRecChange);

 

gnEvent .

 

.

3:

 

using System;

namespace sobit

{

class ChangeEventArgs: EventArgs

{

string str;

public string Str

{

get

{

return str;

}

}

int change;

public int Change

{

get

{

return change;

}

}

public ChangeEventArgs(string str,int change)

{

this.str = str;

this.change = change;

}

}

class GenEvent // -

{

public delegate void ChangeEventHandler

(object source,ChangeEventArgs e);

 

public event ChangeEventHandler OnChangeHandler;

 

public void UpdateEvent(string str,int change)

{

if(change==0)

return;

ChangeEventArgs e =

new ChangeEventArgs(str,change);

 

if (OnChangeHandler!= null)

OnChangeHandler(this,e);

}

 

}

//

class RecEvent

{

//

void OnRecChange(object source,ChangeEventArgs e)

{

int change = e.Change;

Console.WriteLine(" '{0}' {1} {2} ",

e.Str,change > 0? "": "",

Math.Abs(e.Change));

}

 

//

public RecEvent(GenEvent gnEvent)

{

gnEvent.OnChangeHandler += //

new GenEvent.ChangeEventHandler(OnRecChange);

}

}

class Class1

{

[STAThread]

static void Main(string[] args)

{

 

GenEvent gnEvent = new GenEvent();

RecEvent inventoryWatch = new RecEvent(gnEvent);

gnEvent.UpdateEvent("", -2);

gnEvent.UpdateEvent("", 4);

}

}

}

:

1. , .

2. , ?

3. , ?

4. ?

5. ?

6. ?

7. ?

8. ?

9. ?

10. ?

 

:

1. , : , , . .

2. , : , , . .

3. , , , (). .

4. , . . .

5. , , , (). .

6. , . . .

7. , . , . ( 1 3) , . , . . . .

8. 7, .

9. , , . , . .

10. 9, .

 

5





:


: 2016-11-02; !; : 792 |


:

:

, .
==> ...

1669 - | 1488 -


© 2015-2024 lektsii.org - -

: 0.09 .