.


:




:

































 

 

 

 


.

System.Collections.Generic. :

List<T>( )

Dictionary<K,V>( /)

Queue<T>( )

SortedDictionary <K,V>(

/)

Stack<T>( )

LinkedList<T>( )

12

,

( ) , .

:

,

( )

( )

,

, .

,

, .

delegate.

, ,

. : , ,

(, )

public delegate int BinaryOp (int x, int y);

//,

public class SimpleMath

{

public int Add(int x, int y)

{return x+y;}

public int Sub(int x, int y)

{return x-y}

public static int Square(int x, int y)

{return a*a;}

}

class Program

{

static void Main(string[]args)

{

SimpleMath m = new SimpleMath();

BinaryOp b = new BinaryOp(m.add);

Console.WriteLine(b(10,10));

}

}

,

.

, + +=, .

=.

public delegate int BinaryOp (int x, int y);

public class SimpleMath

{

public int Add(int x, int y)

{return x+y;}

public int Sub(int x, int y)

{return x-y}

public static int Square(int x, int y)

{return a*a;}

}

static void Main()

{

BinaryOp a, b, c, d;

a = Add;

b = Sub;

c = a+b;

d = ca;

}

 

13

.

event,

:

public class SenderOfEvents

{

public delegate retval AssociatedDelegate(args);

public event AssociatedDelegate NameOfEvent;

...

}

, :

{

public delegate void MyEventHandler();//,

class TestEvent

{

public event MyEventHandler Triggerlt;//

// MyEventHandler

public void Trigger()//,

{

Triggerlt();

}

public void MyMethod1()

{

Sistem.Console.WriteLine("Hello!");

}

public void MyMethod2()

{

Sistem.Console.WriteLine("Hello again!");

}

public void MyMethod3()

{

Sistem.Console.WriteLine("Good-bye!");

}

static void Main()

{

TestEvent myEvent = new TestEvent();

myEvent.Triggerlt += newMyEventHandler(myEvent.MyMethod1);

myEvent.Triggerlt += newMyEventHandler(myEvent.MyMethod2);

myEvent.Triggerlt += newMyEventHandler(myEvent.MyMethod3);

// 3

myEvent.Trigger();//

myEvent.Triggerlt -= newMyEventHandler(myEvent.MyMethod2);

myEvent.Trigger();

}

}

}

,

, , void

object eventArgs:

{

public delegate void EventHandler(object sender, EventArgs e);

...

class Car

{

public event EventHandler CarEvent;

void SomeMethod

{

if (CarEvent!=null)

{

CarEvent(this, New EventArgs());

}

}

public static void ForCarMet(object sender, EventArgs e)

{

Car c = (car).sender;

if(c.CarSpeed > 60)

{

Console.Write("!!!");

}

}

}

public class EventArgs

{

public static readonly

Sistem.EventArgs Empty();

public EventArgs()

{}

}

}

-

, - EventArgs.

,

EventHandler<T>(object sendler, T e):

{

class Car

{

public event EventHandler<CarEvents> CarExploded;

public event EventHandler<CarEvents> CarAboutToFollow;

...

void SpeedUp(int delta)

{

if(CarIsDead && CarExploded!=null)

{

CarExploded(this, new CarEvents(" ..."));

}

}

}

}

 

14

C# () :

: +, -,!, ~, ++, --, true, false

: +, -, *, /, %, &, |, ^, <<, >>, = =,!=, >, >, >=, <=

+

public static ComplexNumber operator + (ComplexNumber a, ComplexNumber b)

{

return new ComplexNumber(a+b-3);

}

(sbyte, int, float...)

( )

,

Static void Main()

{

int a = 123;

long b = a; //

int c = (int)b; //

}

-

.

:

{

class Base { }

class Derived: Base { }

class Program

{

static void Main(string[] args)

{

Base a;

a = new Derived(); //

Derived b = (Derived)a; //

//

}

}

 

}

: Rectangle Square:

Rectangle rect;

rect.Width = 3;

rect.Height = 10;

Square sq = (Square)rect;

15

(generic)

.

(ArrayList, Hashtable, Queue, SortedList, Stack):

1.

2.

3.

,

Sistem. Collectiions. Generic. ,

,

(List<>, Dictionary<K,V>, Queue<T>, SortedDictionary<K,V>,

Stack<T>, LinkedList<T>...)

List<> -

Dictionary<K,V> - /

Queue<T> -

SortedDictionary<K,V> -

/

Stack<T> -

LinkedList<T> -

:

Static void Main(string[] args)

{

// ,

List<int> myInts = new List<int>();

//

myInts.Add(5);

int x = 10;

myInts.Add(x);

// , Employee

List<Employee> otdel =new List<Employee>();

otdel.Add(new Manager());

otdel.Add(new SalesPerson());

Console.WriteLine( {0} , otdel.count);

}

 

 

17

.Net , ,

Common Language Run-time (CLR).

, .

.

.

1. , ,

2. :

< >.< >.< >.< >

3. ,

, ,

, , ,

4.

.

CLR ,

( ),
.

( )

, , ,

. ,

, , ,

.

, ( ),

GAC(Global Assembly Cache) .

. GAC

,

. .

, , X:

<configuration>

<runtime>

<assemblyBinding xmlns=urn:schemas-

microsoft-com:asm.vl>

<probing privatePath=X/>

</assemblyBinding>

</runtime>

</configuration>

 



<== | ==>
| 
:


: 2016-12-18; !; : 597 |


:

:

, .
==> ...

1589 - | 1460 -


© 2015-2024 lektsii.org - -

: 0.038 .