Está en la página 1de 122

PROLOGO

OUROBUROS
ESTADO ACTUAL DEL LIBRO
CONVENIOS

VII
VII
VII
VIII

I. COMMON LANGUAGE RUNTIME

QU ES LA PLATAFORMA .NET?
POR QU .NET Y NO JAVA?
COMMON LANGUAGE RUNTIME
ENSAMBLADOS Y MDULOS
CLASES Y ESPACIOS DE NOMBRES
PROCESOS Y DOMINIOS DE APLICACIN
EL SISTEMA DE TIPOS COMUNES
TIPOS BSICOS
VECTORES

1
2
3
4
5
7
8
8
10

II. PROGRAMACION ORIENTADA A OBJETOS


ABSTRACCIN ORIENTADA A OBJETOS
ENCAPSULAMIENTO: DATOS
UNIDADES, PAQUETES Y OTROS TRIUNFOS PARCIALES
LA MULTIPLICACIN DE LOS PANES Y LOS PECES
ENCAPSULAMIENTO: COMPORTAMIENTO
UN PEQUEO CAMBIO EN LA SINTAXIS
HERENCIA
POLIMORFISMO
LA REGLA DE ASIGNACIN POLIMRFICA
MTODOS VIRTUALES
LA TABLA DE MTODOS VIRTUALES
LOS LMITES DE LA TECNOLOGA
LA SINGULARIDAD
III. CLASES Y OBJETOS
IDENTIDAD
QU HAY DENTRO DE UNA CLASE
VISIBILIDAD
CONSTRUCTORES
INICIALIZACIN DE CAMPOS
EL CONSTRUCTOR ESTTICO
IV. TIPOS DE INTERFAZ
HERENCIA E INTERFACES
IMPLEMENTACIN DE TIPOS DE INTERFAZ
INTERFACES Y POLIMORFISMO
V. ESTRUCTURAS
GUERRA AL DESPILFARRO DE MEMORIA
CREACIN EFICIENTE, DESTRUCCIN INDOLORA
LIMITACIONES: CONSTRUCTORES
LIMITACIONES: HERENCIA Y VISIBILIDAD

12
12
13
14
15
15
17
19
20
22
22
22
22
23
25
25
25
27
28
29
31
34
34
35
37
39
39
39
42
43

MTODOS VIRTUALES Y ESTRUCTURAS


INTERFACES Y ESTRUCTURAS
EL SAGRADO MISTERIO DEL BOXING
VI. TIPOS DELEGADOS
DELEGADOS
CADENAS DE DELEGADOS
LLAMADAS ASNCRONAS
VII. COMPONENTES
COMPONENTES VERSUS CLASES
PROPIEDADES
INDEXADORES
PROPIEDADES CON IMPLEMENTACIN AUTOMTICA
EVENTOS
CLASES PARCIALES
MTODOS PARCIALES
VIII. ADMINISTRACION DE MEMORIA
RECOGIENDO LA BASURA
FINALIZACIN Y DESTRUCCIN DETERMINISTA
PRECAUCIONES EN UN MUNDO FELIZ
IX. GENERICIDAD
TIPOS GENRICOS
CLIENTES Y PROVEEDORES DE TIPOS GENRICOS
GENERICIDAD Y RESTRICCIONES
MTODOS GENRICOS
CMO FUNCIONA LA INFERENCIA DE TIPOS
NUDISMO Y COVARIANZA
GENERICIDAD Y TIPOS ANIDADOS
TIPOS ANULABLES
OPERACIONES CON TIPOS ANULABLES
PROMOCIN DE OPERADORES
X. ITERACION
EL PATRN DE ENUMERACIN
ITERADORES
COMPOSICIN DE ITERADORES
MTODOS ANNIMOS
EXPRESIONES LAMBDA
EQUIVALENCIA ESTRUCTURAL?
RBOLES DE EXPRESIONES
XI. REFLEXION
SISTEMAS HIPOCONDRACOS
INFORMACIN SOBRE TIPOS
REFLEXIN Y ENSAMBLADOS
MANEJO DINMICO DE INSTANCIAS
ATRIBUTOS
DISEO DE ATRIBUTOS
REFLEXIN SOBRE ATRIBUTOS

44
45
46
49
49
52
53
56
56
57
58
60
61
62
65
67
67
68
70
72
72
73
74
76
76
77
79
81
83
85
87
87
89
91
92
94
96
96
98
98
99
100
102
104
106
108

INDICE ALFABETICO

111

A dream is an answer to a question


We haven't learned how to ask.
Dana Scully

!" # $
&$
&
!

%"

"
%"

. %
/
$

. " &
!
" + "0 $ 1
)
)
$
$
!
. '
"
"

)
# ) +
$

" %
#
#
" '
& (
( # )!
-+
$

!
(
"

( -

(
&
.
+ # 5#
"
" "2 " 72 ! $

3 ( 4+

&

3
6(
%
'
"

"

2
#

&
)

" $
) %

(
"

"

# (
"

-(
.

)
.

"
!
. " &
'
2
. %
"$

#
" )
"
+
"+ 2

&
"! !
*+ ,

. '

A )!
.

"

.0

" $

$
.0 (

& 9:;<
"
2
)

) (

"

8
"

"

"

+
'

&

<=>>?@
2 ..

2
2

)
/

Programacin orientada a objetos$

Clases y objetos
Tipos de interfaz$

"
2
8
&
"
< "
" +
2
B$ C
" 4
"
2 Estructuras
& ) clases parciales 9 ) ) "
!
"
"
2 Reflexin
") 2 Iteracin
8 3$* #
"
8
") $

"
'$
) " +8
! "+

Programacin orientada a objetos (

2
<#

+ )%
"
" #
!
$ #
.

. (

@$
B =$>$
&

&

+
)
#2
)

"
"/

'$
& "

"

"(

& "
2%
"& "
. %
& .
&$
+
" 4
"
$

$
(

"
" #

)
(

.
'
.

"
$

/
(

(
3
.
/
)
)
. +. 4 +
(
# + .
"
$*
" %
.)
( 3

."

(
. 2+

"
"
&

(
&

& . "

'

D 2
." E
2"
)
) $

'

"

&
&

"! !
+)
"
$
# "
8 3 ( #+
/
# # #
) $
.

"

&
")
"

)
%
-

'

public class Triangular : Chip, IOscilador, IConfigurable


{
public double Voltaje(double tiempo)
{
// Implementacin de la onda triangular
}
}

")
'

"

)
&
8 $
F

'
"
0 " #

"
.

"

7
&

"

$
#

$
.0

"
8$
'

.
$

"
!

$
(

$ &

(
+(

# $
*
!!!"
#
!!!" ##

")

" #
"

=>>?

1
1 G

$
) 3)
. !

+)

+ "
(

" $

.
"

# )
"
"

.
#

"
)

"
2(

+
#

%. (

"

.0
(

"

(
" $
"

"
$

(
$

& I$>
"

% A

)
0 "
&

"
)

)
%

"
(

. % (
"
)

. % +
$ KF - $
" %$
"
"
#
"

" ,

"

*$ C
$

*J

"!(
" "
.

/
#+
*J

"

"

"
$
.

*J$ KF -

. "

"!
A+

H D(

&

"
$

"
" $

)%

#
& =$>
*J + (
)
servicios corporativos (
"

( 3

&

"

"

HD

# &
3
)

(
)

"

"

( -

"

"
(
+(

)
.
'

HD

. "
'&

"

%"

2
"

"2/

.
" "
E H 8 "&
" + # EH %
# )2
D*
)
EH
&
.
"
E H 8 &"
) (
DA" E H
+&
' .
4E

(
&

'

. (
(

"
&+

'
. % #+
(

&

"

(
L$ *
$
"

" +)
.

)$
A+

"
)
" $
% &$
"
M

&
"

%
" '

"
"
N #
$
$

$
% &$
" "
+
& .

" (
#

"

.
)

&
'
2
%

"
+
.

.
)

%"
"

(
+
"
8.

& .
% &

"
+

.
(

&$A +
.
(
. -

&/
+
0 "
$

) (
" #

"

'

+ " "
" "
& =$>

&
&
" $

))

"

'
+
%

&"
#

( (

"

"! "

"

.NET es el nuevo sistema operativo de Microsoft

8.
" $* #
)
"

.
(
#+
(
.
"
&

&
!

*J
+*

$
M
"

&

/ # +" #

!
. .

$
"

"

."
"

+#

" "
2 # )!
& .
O
"
" "

"

N (
"
$
)

"
"

'
"

+#

#+
&
' /

"
" "

"
) $
O
+$
$A+
)
4K ( "

"

% $

.
. %

O
"
" +

. (

.NET es Java, pero bien diseado y mejor implementado

$
!

#
#
+" +)

3
$

%
"!

&/

"

"
)

"

&
% &
+" +
NP
. !"
O
!)
$
)
$
(
"
) 3
$
"

"
)&

*
&

+
"

"

. "

&

"

"

!
.
"

"
-

0
.

. %"

0
%
8

&
$

&

"
(
%
. " "
& (
"
% &$
& $ K1
O7*
O
) $
. $
. O
.
"
% & (
" +
$

bytecode

"
"

1
) +
)

" #

nunca

"

%/
bytecode +

"
.
+

"
& .
$O
)

applets

&

(
& !

" " /
(

& .
$
& .

"

#+
. "

+ +
"

Java Virtual Machine$

(
3

O7*
!"

"
+ "

"

Common Language Runtime

+
& )
$

"!(

# )2(
.

4%

)
) "
applets +O
#
"! 2

)2

") .

#
%

.!
&
&

$
.!

/ K( #
M
N .+

.
.

'

.
(

%
M

##

Q "
"! (

:$:
) $

.
"!

# )

2"
4

"

& "!
N Q "

" %
bugs

%"!

'
"

/
$

&
"

&

O
$

. "

"

"
+

(
" 5 ) "
%
!
"!

"0

"
"

" +) %
8 3
"
(

$ DataSet
-

)
"

) $
.

"

+ "

servicios corporativos$

!
(

$
O
O
0 "

.) (

"

&/
"

&

" O= 4 +
"! (
M
.
"

"

&

(
M
"

.
(

data binding

&6+

2
"

0"
M

N
"

(
N

"

(
"

% ) "

"
N =>>>
*J$
8
%

) O

En .NET, el sistema operativo y el entorno de ejecucin colaboran estrechamente

&

"

"
(
" )
) &

"
"
$

(
4
) +"
) $ * "
(
(

!
+
#

" #

-(

(
-

"
" (
+ +
"
( -#
"
) +"
.
)
$

"

2
+ ) .
(

" #

C #
. /
"
"2 "
" $C ) " +
#
& .
"
" 4 )
"
"
.
+
+
"
& %
$
#

") . (
)

"

"
&
"
"+
# "
$
+
(
.
&
$1
' ( #
"
" .

"!
) "
) %
( - "
"

&

# & '

K )
"

"

& .
& .

"

(
& .
&
)

"

) %
& .
$

#+

"

))

&
.

%"!
+ !

$ KF A+

.
/

( &#

just in time

8 "
# )!
" "

$
)2
!

&
" #
"
. " $
%

" '
$

"

)
)
'"
4
"
(

2 .
(

"
.0
""-

+
(

$
""
(

"
"

"
Main

"-

"
+

'
"

(
#

.
'
& )
( 3
."
, .
" '
% &
MeDaLoMismo
& (
$K !
& .
.

* +
)

(
+

"!
(

.
%
" "

"
" "

9
"!

(
(

" )!
!
!" (
"
"
"
'$

( 2(

& .

.
& .

&$

&

&
&
!

"
" "

&

(
"
2 . "

2
"

%"
$
& # +(
%"

&$

N
) %

2
"
@+

" "
) ( #+(

& .
$

!$ D

$
&

!"

" #
ngen

"
)

&

)
"
) /
+
"

+
) '

&

(
$

#
"

# )!
(

"

&

"
"
"
) #
(
& 8
"
) $
ngen$
" + "
" $
& =$>
.0 " "

&
%

& .

MeDaLoMismo

"

# & '

" .

/
.

"

!
+

& .

/
"
& .

"!

) %
ngen )
"
2 (
" #
$
#+
"
"
(
+
'(
%
"
&8" % &
#
Q +
& .

"
"
"
ngen$ A +
% &
%"
%
&$
" "'
. &$
!
")
.
inlining
8

"

(
&

O
"

& R
%
"

"

(
" %/
. % Q + :$
"
.
) %
&$
$
%
+

#
"
&

& .

& .
$
(

"

"
%

%.
"

(
&$
2 $

&
" %
' &
"
"

2
"
" "
"

' " %
$
) (
%
'

) %(
"
(
& .
& +
)
"!

$
$
+

Complex

(
))
#
"
))

"
enlace esttico
& .
"
"
5
6$ " "
" %"
/ ." (
" %
0"
" %$
. %
" JJ
. "
"
)
))
$
M
N
2
#
8
& lib$
&
)
. " (
& .
" " se copia
$
(
"
) "
" '
3 +
))
!"
"
M
N
( #
Complex$
. 2
+
&
")
N

##

))

!"

%
0"
"
" " "

Complex

3
!

.
))
.

2"
&

%$

%
(

$ KF

"
!" $
!
"
"

"
% (

") .

%
!"

)
"

") -

))

" $
#
$

"

"!8"

"!

& .
&
) %
"! (

"!
&

"

"
+
"
.
$

) " "

/
Todo avance en Informtica consiste en aadir otra capa de indireccin.

&
#

2
" (
$

'
#

. "
")&
")

"

"&
)

&
") & " + "
")
+
7

(
!

"

."
"&

") ")
$

"
#

(
"
3

"

")
.
"&

"

'

"

2 "

"
++
$

. %
"

!"
"&

"

# ) 2(
"&
"
$

2
!"

"

%)
"
") .
$
/ "

"

")

") -

)*+,

+.

"

"

)
(

&

7
&

"

")
"
+ %
&
$
$

")
) %
"&
"&
# +(

" " ))
"!
"&

"

"!

"
))

" &.
&

" mdulos +

#
2
" ensamblado/
!

%
8

) %

KF "

")
"

/
$ A + ") +

+"

")
"

!
")

"

$
"

+
")

.
"!

")

" /

System.String

System.Data.SqlClient.SqlDataAdapter
Microsoft.CSharp.CSharpCodeProvider
IntSight.Proteus.Stargate.Entity

#
)
")
. (

"+ 2
.
"
")
&.
)

%"

. % (
"

.0
"
")

"

"

" ,

'

. %

0 "

espacios de nombres

) .
")

"

namespaces$

")

"

"

")

System.Data.SqlClient.SqlDataAdapter

")
")
")

SqlDataAdapter$

)
SqlClient

"
"

) "
") $

")
")
")
" "
) "
")

( $
!

"

. .

System

Data (
System$

"

52 6(
5

/
"
" "

'

'

")

"

")
"

(
")

"
$

"

+ "
")

.
+

")

$
K &"

"

#
& .

( -

")

ildasm

"
"

&
&

"
'. ! $ *
%
8
+
Reflector
.
!. /

"
") .
'1

www.aisto.com/roeder/dotnet

" "
" .

)
& =$>
&/

!)
"&

#
"

system.dll$

")
"&

System$

"
(

%"

;$=$;T$> +
$ ( 2

"

)%
")

" .
")

Reflector

& "!
"

"

"

&
Microsoft.CSharp (

##

.
"

CSharpCodeProvider (

0)

$
"
%

#
"

&
"! #

M
N
"
$
#
9threads@
+$ )
( #
(
"
$
M
N
)
# + !
"
" &
" "
$
' &
# " "
"
$

" "
"!

"
)

dominio de aplicacin

"

(
&

. "
#
. "

"

)
& .
(
$

"

"

"

.
$

& . (
& "

.
)

$
2

/
$
& .
.
") .
4
.
.
!"
"

"

#2

M )
!.
"

"
+

5
# ) "
"

%$

"
")
" + 2
+
!$
.
$
.

" "
"

verificacin

)
' (
"

6
&

&$
(
(

# "

'&
5

"

'

"

$K "
$
% &

"

+) )
+ %
$
" "
% $
# +( #
4

&$K #
+ "
" "
"!$

'
"

" "

"
"

&

#
(
0

'
'

& +
&

"

. "

#- "0 $
"

"

$ %

"0 /

") .
%
#
'

' &

"!
#

&
"

N/
/
" "
" (
)

%"

$ %

"
8

M
+

)
#

$ %

0
"

application domain 9AppDomain@


/

"

N "

"

&
!

$
#
))

. "&
+
.
& . (
"
&$
$

.
!
"

%"

.
"

'(
" 2
.
"

"

&

" " (
"
&$

&
"
$
)

( 2
" +!

"
"

&

"
&
"&
$
" #
.
& .
"
)
" # $
.
& .
"
.
& . "
.
.
& .
"

+
' .0
$
$

" "
"
"

" +
#
(

2 !

.
+

. "
&
.

"!

&

" "

)*+,

$
&

(
" "

. %
+

"
)%
/

$
" " "

)%

Common Type System 9


'

"
.
@(

2 )
. " "
")

"
"

(
)

"
&

"!

+ 8

0 "

. %

/
'

)!
O

&"
'

"

"

4+
") -

(
.

. "

"
&

"

( -

! $
"

%
"

"
" $

"
%"

"!8"
$1
(

999.ToString()

T
-

5)!

&
)
B

2
"

6+ !
(
$ " "
"
.
/

. %
"

##

2
String

8
/

"

&

"

& To-

999.ToString("C")

K ! .
(
4
( "
' "! 2
(
2 )
)%
+
)

8
"

(
.
"

3 "
(

)!
8

#+
6/ )

"! "
"
"
"

.
:? )
I= ) $ A +
tipos de valor
"
"
.
"
+

)
)!

)
"
")

(
(

&
&
0
&
(&

A+
" $
2"

#
.

&$
) %

%"
"
)!

/
+
'
!
!
!
!
!
!
!
!
+
+

"!

"

Common Type System$


B
"
CTS/

"
0
.
5
5
12
12
67
67
28
28

,
/
0
12

3
4

8
5

"

(
&

2
(

"
Common Language Runtime +

#+ .

"
(

&
/
)!

compuestos (

.
"
&
"!(
I= ) $
(

B$

.
. "
'$

$%
System.Boolean
System.Char
System.SByte
System.Byte
System.Int16
System.UInt16
System.Int32
System.UInt32
System.Int64
System.UInt64
System.Single
System.Double

( &

)%

8
"!

"

( 2

"!

. %
+ )% $
.

5)!
"!(

&

%
& .

")

. %

//
System.Int32 i = 0;
//

K " .

)
//
for (System.Int32 i = 0; i < 10; i++)
{
}
//

*
7
. %
.

#
G

) $
"
$
4 "
"
(
"
(
+
" & .
"
")

.
"

"! "2 "


(
"
&$
.
. "
"

&
2
$

,
2
.
"
+(

!
(
7

. "
#

. "
B

(
7

+
"
)
2

+
G

A "

)!
5)! 6
3

# &

3
"
" # "! "
"+ 2

/
0
9
'
+

"

3$
175

") )

"
(

)
8

&$

A+
$C " "
. =4
" (
B/

")

$%
System.Object
System.String
System.Decimal

(1

K #+

(
& =$>

)
. "
boxing +unboxing
. #

"+

boxing$

"

$%
System.DateTime
System.Guid
System.DBNull

/
:
'
.

$
" (
)"
0

0
2

")
"

+&

);9)

"

"
"

DBNull/
DBNull$

)"
(

&
. % "
'
2

(
'

"!

"
"
" 3 + " %
&
)
&$

2 ./
"
" "

vectores 9arrays@

%"
!
"!4 +#
/
8
+
&
(
B
T[]$

2(
" .

"

&

)*+,

'"

&

! '< 1=

>

>

")
. $
$ *! )
8
) . $ "

"

"

< JJ
/

$
2
# )

&

T'

7=
'<
! :

"

$
. %$
. "

?
*

"

"

"

// Esto sera en C++


int vector[];
// Esto es C#
int[] vector;

2
)2

&

:>

"

"

8 3
.

2 )
2

")

)
) $

"

&

##

< JJ
'(

$ #
"

"
+

"!
!
B 9 8

. "

'(

) +
"!$

#
.

&

O
(

&

JJ

=$>@/

// Esto es C++. En C# no est permitido.


int vector[7];

'

int[] vector1 = new int[7] { 6, 5, 4, 3, 2, 1, 0 };


int[] vector2 = new int[] { 11, 22, 33, 44, 55, 66, 77 };
int[] vector3 = { 111, 222, 333, 444, 555, 666, 777 };

8
)

"
"+
%" /

+
)

#
$

)%
+
&"

$
8
'

&

"-

"
Length

string[] dias = { "Lunes", "Mircoles", "Viernes" };


for (int i = 0; i < dias.Length; i++)
dias[i] = dias[i].ToLower();

"

"

"

+"
&

"

&

"

foreach (string s in dias)


Console.WriteLine(s);

"
" ")
Array

"

Common Language Runtime


System.Array$
Array

") .

")

""

(
"

)
(

"-

!
/

(
$* #
Resize

"
"%"

string[] dias = { "Lunes", "Mircoles", "Viernes" };


Array.Resize(ref dias, dias.Length + 1);
dias[dias.Length 1] = "Sbado";

)
!"

"
+(

!"
"-

"
")

Resize

(
) $

::

2
R

1 R1 *

" .
) ( - .
( #
)
.0 "

"
( -

)%
2 .0
. "
&
)% 6$
.2
$
+ " # )
!
$

"

5
"
&

. " &
(
"
2
) " (
$ $ $(
#
%

(
") .
) ) (

)*+,

.
" " %
"
)
$
# +(
2
1
!(
%
"

opcional )
* 0
3
*

!
@
*

$
&

) " "
& . + 8
$ K &"
"
8)
(
0 "

."

) "
) " $
. " +(
"
"
( 3
$ ") - . !
(

1
-

"2
)
)%

8
) (
)
(
2 ( '!
" +
2" % $
+ 8 $C
(
) 4
") .2

*
)

?
*
B
C

. %
)%
. % "
2
"
(
&
!
)
8
+ 8)
$
( 2+ ! +
. %
&
!
++
.
. " &$
$
"

&
%

. " &
')

"&

"

"
4

. "

$
"

%
"

ray tracer$

) "
8

.
"
"

'
$

"
+
"
'
. "
& .

$C

"!$

ray tracer$

')

))
& .
. " &
))
(
8
)

2
)%

. %
(
2
. "
"

)%

"

"
.
."
$
(

)%
3
" +
(

&

%
&
% & $ K1

"

(
( #

)
2 " "

'

"
.

A
*
$

"

'

)%
(

"
8

+" #
"
.
.
) (
2

"
"

%"

' *

"!
)

*(1

/ " .
."

(
.

"
" quicksort

"
"
.

"

$
"

'(

"

"
"+

"
"

4
" "
) 2" )
$K
E
#
( (
D

comparar

"

"
/

"

.
"

"
!"

+4
.

. "

(
"!
D
(
$ K ( -#
"

"

" (
"

"
!"

&
"
. " &

se expresaba con dificultad

#+ .

(
$

"

K( - (
"
(

.
$

"

) "
* "
"

. "
) +!

. %

"

")

" +

)
. "
"
F '!
K

" #
esto no vale$ A +" #
& . +
8 #
" "
"
" !
(
esto es una porquera usted es un genio, amigo$
& .
+
(
2 $ K" .
(
2 (
"

& # +(
"

( -

") -

2
+
. "
' "

(
"
"

"
"+

. " (
.

$
) '
"

&
. "!

"
"
. " &
"

" +

abstracciones

&

" + "

"

%"

5.
&/

)
"

6
)
I$> +
"
)% $ "
2
# )2
& (
)
0
#
"
variables/
)
$
& .

8 $
$

2
"

"
) (
. )

"
'$
3
(

/
var
DesplHorizontal, DesplVertical: Integer;
CursorX, CursorY: Integer;
NombreFichero: String;
GuardarCopia: Boolean;

*
(

(
. "

"

(
"

!#

')

:I

) %

)
( . (
+
)

(
"
)
"

" # ) !(
$

.2
2
+
) $
"
)
4+ " + ) ) (
.
"
$ # +*
) +
MxN
$C
0
# # )
$ "
'( # + ( #
")
.
!
) +
2

2 ( #
" '
.
+
!
' descomposicin modular$
(
8
"
"!
(
) $
"
.
"
%/

"
"

#
9D "
8

" $C
%"
. )

-)
!
#

&$
/

"

"
)
&

"

records

3
"!
/ )
"

"
) $

(
(

0"
&

( 3

"
+# )

#
"

"&

. %(
& .
"
structs
$

. '

(
"

&
. "

&

"
E@$ 1
"

"

type

" #

%
# +"

"
2

.
+ $

Posicion = record
X, Y: Integer;
end;

var
Desplazamiento: Posicion;
Cursor: Posicion;

&

"! .
"

"

)
2$ .
"

! .

"

.2 %"

# +"

+
"
"

&

"
(
# )- "

"&
"
'

:;

'
)
$

"!
$

"

" "

8
$
"0 + )
$ #2 !
"
*
+
(

8 "
" "2 "
2
.

"

#
# )2

) '

+!
+(
8 "

G%
?>

"

)
" .
&

"
.

"

G
#

3
"

(
2
)

"

8
(
"
)

& "

"!
0)

' *

.
#

*(1

&

) '

#
(
. % decentes
'
" $
8 2 "
"
#
"
$K ( (
+
"
"! I$
(
(
.

. % (
-

2
%"

# "
"

&
-

" 2 compilacin por separado


"
" " 4
(
2
(
)
)
)
"
" &
.
. ( #
"
)
" +! #
'
$

$
*

) "
'$
!
*

#
)
)

"!
)

! "
& "

"

#+

/ &
"

0
$

(
"

) "/

. )

"
%

) $
# )
0"

"

. )

) "

%.
"+ 2

)
')

9packages@
+ ) "! (
$
2
tipos de datos abstractos ADTs$
(
2
)
"
#
" "
&
$ K !
2 .
.
) (
)
+ . "
(
)
.
$
.
)
"
&
'
D
.
.2
(
E
# )2
"
(
.
. "
+"
'
"
"
. $
(

(
" +

" )

# )2
")

2
"

(
$
"

)*+,

")

% (
") - # )2
"

)
%
" "

"
"

"
"

)
/
.2

"
(

2(
)

(
"
"

"!

&$

)
2

) (

. "
"

"

( (
"

2
&

"
)

*
&

Editor 9
?

* *

)
. % 8

.
"

GO

+ . +
"! $

" *

#)
# #

"

" # "!
2
"!

"
)

:S

genericidad #

".

JJ4
.

&
. "

fichero de texto

5
2"
dispositivo
%.
$ A +# ) 2"
(
. " "

.
8

)%

&

& #
$
$
#
3 ?V +
+ "
&"
" $C " "
(

2
" -

) %
#
"
(
") " "2 "
(
streams
(
"
)

8
L
"

)
%"

".
"

$
2
"

)
#

'

" flujo de datos$


Text

" "

. $
" /

)
%"

record

"
(

"

# ) 2(

)
.3 /
6
# )

"
)

)%

"! )
3 ?V # )

. %$ 2
"

"

&

( 2
"
. % " $
"
# )
.
"
. %
. " &
3
8
%+

"
3

"
'

+
.

") . $

Zona de datos

Cdigo ejecutable

.
/
( - " 3
( #
(
2

"
(
8

&

"

"
" Assign
$ )
(
"
#
" " $ *!
&
)% $

)
"
#+
. "
(

"

:?

quicksort

2 " "
. "
! )
+
( " "
- $
'
. "
" Open Read +Close4$
(
)2 %
. $ K1
) "
2 $

"!

#
) 5

") - comportamiento$
.
(
. " &

"

)2
#

"

+ ")

"
#
)

/
)

'

.
"

( 3

"

&
) datos
2
"
$
( 3
$

& # )2

"

"
) "

&"

" "
" "
)%

(
&
2
"
+(

AssignPrn

"
6/
.
2

"

"

!
&

(
"
"

!
" +

&$

,
&

' *

*(1

( 3
. "

'

2 .
type

. +

+
" $

+ &
%
/

."

" "
. "
$

(
. "-

(
(
)

Vector = record X, Y, Z: Double; end;

'

.6

) %2

procedure InitializeVector(var v: Vector);


procedure SumVectors(var result: Vector; const v1, v2: Vector);
function VectorLength(const v: Vector): Double;

" .

(
+

"

# .
+

") '

+ "
'

!
"

"
) % +# " '
+
)- "
"

"
$ 2

$
# )

'

(
"

# )2

+
" # "

&.

&
(

) $
(

"
)
!) " # )
"
"
S$S
2"

$K
(
)

type

&
comportamiento

&

Vector = object
public
X, Y, Z: Double;

end;

constructor Create;
function Length: Double;
procedure Add(const V: Vector);

" "

"
"
%

.
'

%
& )
!"

!"
" 2 $
") - #
" Length
$
")
(
") "
constructor$
"
")
"
. $
7"

&"
" #

&
(
" . A %) .
"!
# @$
#

9
#

)
')

%(
# (
.
" "

. "
& .

))
. 2

"
"
%$ .
" $
#

)
Vector$

")
'

"

/ VectorLength
"

%"

#
!")

$
.)

' &6

#
!"

" "
)
+
.

.
)

" Vector
(
$
2"

$
"
"

)
.

# )
(
& (
&"

Vector/

:U

var
V1, V2: Vector;
Len: Double;
begin
V1.Create;
V1.X := 1;
Len := V1.Length;
V2.Create;
V2.Y := 1;
V1.Add(V2);
// etctera
end;

A "
#
"
")
$

// En vez de InitializeVector(V1)
// En vez de VectorLength(V1)

"
&"
")
mtodo$ )
2
"
" " $

!"
!"
(

!"
")

" 2 /
)
!"
" 2
Create
2"

") "! .
&
. /

") .

" 2

+
(

)
"
SumVectors$

procedure SumVectors(var result: Vector; const v1, v2: Vector);

+
"

'
# ) 2.

"2

(
"!

"

$
/

function SumVectors(const v1, v2: Vector): Vector;

(
&$
"

)"
"
"
2" "
"
3 $
8
(
"
(
"
'
"
/

+
)
"

"
'

"
"

"

"

" "!
(
4
"
#+
! + "
&
& .$ )
componer 8
"! " % $

" "

"

'
"
%"

SumVectors(SumVectors(v1, v2), v3)

&

2 "!

"

2"

"

"

/
SumVectors(v_temp1, v1, v2);
SumVectors(v_temp2, v_temp1, v3);
454%

* 3%*364/+*

,
#

-,
#

-,
!

) "
+
+
.

."
" +

"

. "

&

&

)
%
")

' &

$
)
%

"

!" +

#
"

") $
"
# )

&$

%" %

."

&

)%

procedure Add(const V: Vector);

"
.

:T
-

%"
") $
"+ 2

"! )
"
2 " +
#

D "
+'
"
.
-

E +
" #
) 24 7 # "
(
"!
(

.
)

"

"

.
"
+ 8
( "!
) .

")

ray tracer

' *

$K 2

" % (

*(1

2 "

. "

&$
# #

&
!

. "

) $
&
"&

)%

#
. "

" "

"
')

#
)
$ KF -

"

"
4
"

&

'
.

K*

" %
$
$
%

" "
(
# )
" .
) ( )
"

2"
"
"! !

"
(

#
"

"

" .
"

D 2 +

"
&

"

"

5 (
#

"

%
. "

"

) #
& " /

"

E KC ( -

"!
7
"

"
(

)% $
" '
% . % @$ ") ") $
" # "
&
B
+ .
(

4
!

"

&
"

&

) "

"
. " &

(
. %

( " " '


" # "!
"

" %
(

9event driven
B

*
%
&
" %

"
"

9 (
)
&
.

# )2
" 6$

"
#

2
# .!"

"

'
/52 "
) 6$

.
&

)%

herencia$

.
.

'
(

" "
.

(
M .

) "
9
(

.
) .
.

# )2
"
&
&
. !

.
$
$

'

(
%

2
&.

(
)

# #
&

# #

" +"
'"
"

'&
+
$
'(
' 8
. " &

felidae

(
"

"

"

"!
(

"
-

"
!

(
% ( 2

che, qu

"
"! (

$
( -

/
"

X+
-

) .
(
" #

(
'& +
#
" +
"

)%

/
.

)
"
&
) .

%
"!

"

+ 8.
G . (
.
(
# N

+
"!
$

&
@ #

felis
.carnvoro "

.-

. "
$

+% ( 2 /
felis catus

puto mundo!

"
) .

"
.2
&

%
"
# )
.

-"
"

filsofos$

&
%"

"

") .

"
"

"

)
3
.

$
G)

4 +(

. :V

. "
#
# "
(
%"
"
.
"

&

)%

"

.
"+

@
"
(
B/
2

&

" "
#
3
" "!
E
") .
"
"
$K
" ) 0)
(

+(

"

Punto3D

"
$
3

"

#
K ) 2
"
&
"! .

'

"
(
8
.0
( A+8
'

$ DC
. "
.

$
"2 "

"

"

"
"

" $
2
/
" "
(

"

(
(

Punto2D

" '
$

&. $
92
")
.
I

%.
(
2(

public override double Length


{
get
{
double l2d = base.Length;
return Math.Sqrt(l2d * l2d + this.z * this.z);
}
}

.
. "

%(

&

)%
) (

#
)
#

" polimorfismo$
real
(
$
. (
"

/
public class A
{
// campos definidos por A y heredados por B
public A() { } // Un constructor sencillo para A.
}
public class B : A
{
// campos introducidos por B
public B() { } // Un constructor sencillo para B.
}

"!
"

"
) "
"

"
8

!"
A

'
"-

"
!

public class C
{
public static void Metodo(A parametro)
{
//
}
}

"

=>

%"

# "B$
/

' *

*(1

C.Metodo(new A());
C.Metodo(new B());

"
"-

. " "

'&

"

A +B
Metodo
B

+"

"
! ") -

" "

"

"

"
"

" "

"
&

$
)
.

") . (

"

&$ " .

C/

"-

public class C
{
public static void OtroMetodo(B parametro)
{
//
}
}

.
3

"

"

" "

. 2

/
C.OtroMetodo(new B());
C.OtroMetodo(new A());

// Error de compilacin!

B +

)
B$

"
.

- "

) (
A K( -

&

"

A "
#

'
"

"-

(
)

%"

"
(

$
"-

A/
public class A
{
// campos definidos por A y heredados por B
public A() { } // Un constructor sencillo para A.
public void Metodo()
{
// Manipulamos el campo amarillo.
}
}
public class B : A
{
// campos introducidos por B
public B() { } // Un constructor sencillo para B.
}

) "
)%

(
"-

Metodo

"
(

aplicar

%.

. "

&

A/

A a = new A();
a.Metodo();

=:

&

#
+ ") -

"

B
tiene (

. (
"$

) #

) /

B b = new B();
b.Metodo();

C
& .
(
B

"

$ & (
. "

Metodo

"
& .
$

"

"

"! !
A & "

" "

"

8
( % "
$
"
" "

"
#

5 . 6/
.

Metodo

/
K1

&
#

VMT

"

2"

.
)

==

"0

Cdigo ejecutable

)%
"-

" "
$

"

) "

! 1

*(1

"

"
)

' *

"
"

(
$

& "

"

!
&

"
)

. "
(
0
)
" "!
. !
2
'
)
%+
# 2#
") - 4

!
(
&"
)%
# !
)

(
) %$ G

" %
& (
&
!

. "
!
(
2
2
"

"

"

"

( 3
3 $

"

"
0

#%
#
. "
)
&
. "

!
"

& (
"

) "

.
+ +

$
+ +
-

" "

+
'
") .
" # " $

) 2
! . " +

. " "! " % (


8 /
# "
A "
)
&
$
&
" %
&
"!(
(
) 5 %
6 # & .$
.
.2
"
"!(
2
"
5 !"
)
#
64
(
)
2
") ". 3
&"
"
&
$
"
(
( 3
. "
" #
! )
"
.
"
) .
$

'" +
"

"
"
!

" %
) " $
) %
" # "+ (
3 $ 8
# &
(
) +
.
' $
"
"
# &
&. /
"
#
%
$ KC
)
. " #
( 3
(
( 2
"
)
.
"
4
!
2
")
8
)
)
/
. "
)
5" %
6
!
"!
'
.
. '"!
.
" %
. "
+
" " $
"

"

"

+
!"
+
) %
"! %
. !
"
&
.
(
"

+
'

'
' 3 +
.
A "
!
.
&
&"
"
. "
"
!
(
' !
"
""
* % $
!
!
(
.)
!
)
" % . $
! ") (
! "
"
'
&
!
(
. " !"
. &"
&
(
#%
- +
! 5" %
6$

=I

" %
"!
+

/
.

- "

" %

4
"

=;

5" %
5# "
'
"

$ "
8 !
6$
" ! 5
6$ 7 !
( 3
+
8 &
5# "
6$ C
4

"
)

) ) "
.

4
2"
3

' 2 $

!. $

# )!

$
(
6
.

"
" %

. !
-

!
(

3
B

Q1

. "

clases

A+
.

. %
) "

/
" O

"!
"
&

(
$

"

# )

#+
(

(
clase$

)
,

%"

2
semntica de asignacin por referencia$

" $
"

. (

"

"
K

&
2" "
" "
+

$
&

)*+,

)%

/
$
( 3
)% +

# +(

"
)

"

" "
"

&

3
$7

" #

)
" "

"

"

. &"

)% $
&

"
$

tipos de referencia
Common Language Runtime

$
!( #

$
'<
*

3
"

/
!

/
$

")

#)

)% $
/

& .

. %

mtodos

0
)
)%
")
"
" $
"
"
#
$
"
(
%
. . "

+ . '

" "

"

/
8
& .

"&

!#
!(

"
(
" "

"4

2
") - "$

(
"
$

"
+

)%
)
$
" "
"$
"
" aplicar # "- ,
" 2
"'
"
"
"(
%
( # +(
$
"
"
!
(
)

& .
8

)
(

&
"

construyen

)%
. %
9D

4 +)
)%

"

$ # +
. (

E@

8
" #

/ "
& +
"
" ")
& "
"

+
. "

"

"

"

"

"

"

'

3
"

"

2
"

"

"

$
"-

(
"

6
. $

4
"

$*

"

"
"

$
"

(
(

& 6 9raising@

" "
5 " 6
# )
"
") -

" campos de instancia$


"-

") &
"

# )

"
"
$

%"

// Un campo de instancia
public string nombre;
// Un campo "esttico"
public static string prefijo;

"
'

nombre

"
"
#

&

"
(

" 6 (
(
) "
mtodo esttico "
!
"- /
)
"- $

0"

"

#
(
- "

" "
"
#

"

prefijo

"
"
" prefijo
"-

0
"

)
"

8 2

"
" 2 $
"

"
$C "
8 2 "

" 2

"

(
5

"

" ")

&
&
"
$
") . &
# # D
"
+
"

")

" ")
! /

"

'
" .
" .

" 2
(
& (
"

2
.
2
1

=?

&

" .
4 "! "
8 2

(
&
$

'
"
2"
" !
" ")
!

"
"

" +

&

. %
. "

"
$

2 "

(1

"

"

&
" ")

nivel de acceso/

(
)%

( -'

" 3

+
"+

$
"
"
) 2

+
#+

"

$
")

' -

"

"

"

$
)%

$
& .

"

1+
. %

"
(
# " ") $

'

"

) "
"

"+
"0

" #
!

$
$
"

"

&

"

JJ/

" ")
" "
$

'
")

+
+
")

"

#
" ")

&

'

" ")
(

'
(

(
( -

"

"!

")

$
A+

")

" ")
")
(

&
.

'

)
# $

& "

" "

" ")
" "

'
")
.

.
+

&

" ")

" ")
$

")
)

$Q

")
(

"
& #+

&

")

DG

) E

" (
)
" ")

" ")
"
constructores de tipos

"

"

& 8 2

") -

'
0)
(
&
$ ) )
") - (
.
"! "
"
$
. 2
"
constructores estticos
"'+ finalizadores 9 $?T@$

=U

8
!"
#
. % .
"!
%
)

# +.

")
" "

.
"

) .
)

) "
+

)*+,

. %

' &
.
"
&$ ( 2
,
)
. (
8"
"

&
8

")
")
"

"

)%
8

"
$
" "

"

"
0"

8.

.
!"

" 3
Common Language Runtime$
. %
"
#
(

"
)

&"

.
")

)
(

JJ O
'

-"
. %
"
"
" "
$

,
!

$
(

2"
%
JJ + O

"
"

&
"

-(
&

&

#
$
! '<

&
*

./

!"

. "
$

'

./
!
& .

"

"
"
#
"

$G

"

#
#

"

(
-

#+

#
.

.$
./
"
"
"
8

sus

" '

8 2

" 2 $
!"
$

#
#
#
"

(
$

.(

" 2

# "

"

) %
" "
" (
#
.
/

$
!

public class A
{
public A(int i) { }
}

K7
(

"
.

public A(int i) : base() { }

!"
$
$ )

#+
)

'

) "

public class B : A
{
public B() { }

"
.

System.Object +

#
#

$
(

=T
-

) " /
8 (
"
(

"
)

&
)

&

(1

public B(int i): base(i) { }


}

2
!"

"
") . (

(
2 2

public B() : this(0) { }

#
B$

8
+
!"

)
"
"
#

'
" " (

%
# "
.

$ 8
#

"
"

5# "
"
"

# "

$
"

(
'

6
)
8
"
%

/ &
(
%"

" "
")
'

&

$
'

# #

. "

&

# +(

"

"
'
)

" "
"

!
&
%

3
" 2

8
&
8 2
' &

"

(
"

%
(
.

#
7 "

%"

$
"

.
"

"
'

"

"

"

"
(

" "

$ "
"! "

"
"

! .

' &
#

$
%

"

" $

"
# )!

.
)
# " $
(
" !

%$

public class A
{
public A()
{
Console.WriteLine("A");
}
}
public class B : A
{
private int i = 1234;
public B() : base()
{
Console.WriteLine("B");
}
}

" .

B$ K

"
+

&

"

( -

(
B 7-

%
%/

.method public hidebysig specialname rtspecialname instance void .ctor()


cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: ldc.i4 1234

. =V

L_0006:
L_000b:
L_000c:
L_0011:
L_0016:
L_001b:

stfld int32 ConsoleApplication1.B::i


ldarg.0
call instance void ConsoleApplication1.A::.ctor()
ldstr "B"
call void [mscorlib]System.Console::WriteLine(string)
ret

& .
"

.
.

"

) .

" O

Reflector$

"

"

"
"

B$

) (

"
" i
. "

(
"

" +
JJ
2 "
+
#
"

( 2
$5
A6$ G
JJ
) (
$ )

.
. "

(
A

O +
) '$

#$
"

public class A
{
public A()
{
Console.WriteLine("A: i = " + LecturaFutura());
}
protected virtual int LecturaFutura() { return 0; }
}
public class B : A
{
private int i = 1234;
public B() : base()
{
Console.WriteLine("B");
}
protected override int LecturaFutura() { return i; }
}

KF -

B K

"

half dollar, half dollar, one

penny and two bits

"

"

Futura

# O

JJ

A
LecturaFutura

JJ
JJ
"
B
:=I;
(
8
8
&
" i # )2

"

'

"

"-

I>

.
#
"

%
A$

JJ

)
)

+
+
"

"

"-

(
$

" "
"!
%
A

&
) $ LecturaFutura #

"
"
2

JJ "
/"
5& 6

"

"

%
%

'

Lectura-

"

"

2
"
#
'
' & LecturaFutura
"! "

"

!:=I;$

&
(

")

"

)
$

"

)
!

& .
' !
$

"
)

"-

A$
& "!

. )
% ( 2
$

"

(
%
.

&

# O
.
7

+ B
' &

"

( '! "
"!

'
.
)

(1

&
+

"

#
"
' &

8
# "
" $

' &
"
"

(
& .
& +(

"
"

.
"

(
.
. !

!"

"
0

$
"

Reflector$

.
#

'
8 2 "

JJ$

%
(

"
# "

"
(
& . (

(
'

"
"

"

"

+ 3
&

"!

.0

8
)

"
/

public class A
{
public A()
{
Console.WriteLine("A");
}
}
public class B : A
{
private int i = Devuelve1234();
public B() : base()
{
Console.WriteLine("B");
}
private static int Devuelve1234()
{
Console.WriteLine("Inicializando campos");
return 1234;
}
}

%"

'

#2
)
"! $C
")
(
3
!"
B/

"

# "
'

!
!
B

+
"-

'

")%

"
%"

4
"

2
'

$ B
"(

private static int Devuelve1234(B instancia)


{
}

"
&

"

Devuelve1234

2
$

&

'

%
+

" + )
(
(
2"
2
"!
!
!
(

"

$
!
"

"
! 6$

"
( (
(

2# ) "
(
"
! $K

/ (
#
"
!

(
"
"

"
!

#
"+" 2 $

I:

)
)

"

!
" " $
%

!
(

'

! 6

8 2 "
$
!"
+
" "!8"

!
!
!

"

,
"
(

&

public class Ejemplo


{
public static double Sqrt2;
// Este es un constructor esttico!
static Ejemplo()
{
Sqrt2 = Math.Sqrt(2.0);
}
}

"
" (
.

!
"

8 2 "

"
!

"!
$

"
'

") & .

'

/
public class Ejemplo
{
public static double Sqrt3 = Math.Sqrt(3.0);
public static double Sqrt2;
static Ejemplo()
{
Sqrt2 = Math.Sqrt(2.0);
}
}

( 2

") .

D
)
8
. %

!
' &

8
( #+
"

% . # +(
&

"
#

"
"
"

E
!

$
Reflector$

"
(

)
!

.class public auto ansi beforefieldinit A extends object

3 "

&

") /

.class public auto ansi A extends object

A
'

"
" "

" $
$*

'

" "
(
! explcito
(
" "
"
(
8
'
!
! " " )
(
.
beforefieldinit/ (
!
$

)
5 8 2 6

&$
"
(

beforefieldinit4 +

"
"
#+

' !
.
)

' &$
'
#+

( -" "
/

I=

)
"

!
8 2
) #
%
$

&
(

#
"
&

'
%
%"
"

!
" "
"

"

"

%" +

&

.
0

"

"
"

"

'(

"
$ K1

"
!

(1

"

"
+

) %

)
'(

'

%
$

II

4
(

* * Y

JJ
')
2 .
# ." 2

0 "
"

"
&

. "
!

& + (
(

JJ$

.
(

"!

cia de clases$

5#
" ")

" "
#
"

"0

6
+"
"

* #
%
"
"
)
"0

"
.
"

#
"

JJ

#
)
(

. "
)
"

&
!

(
3
"

(
. % (

")
$
" #

(
)

( /

"

heren-

)%
"

. "
" 2
- )
"

"

(
2
"

)
$

.&
"

"

$
#

$
(

!
-

"

!.
$

N
$

"
" $

' #

"0

clases abstractas$

&
2"

.
"
(

")
"
'
"
Oscilador
"

" .
& .

"!
&
. "
)
"
"
"
/

&

&
"!

. "
(

"

/
#

" "
3 % ( 2
9 !
"
"
.
. "

'

(
.
#

$
$
@
(
2"

"

public abstract class Oscilador


{
public abstract double Voltaje(double tiempo);

%"
&

07

// Otros miembros, no necesariamente abstractos


}
public class Triangular
{
public override double Voltaje(double tiempo)
{
// Implementacin de la onda triangular
}
// Otros miembros
}

"

8 " +

)
$

,
+

. (
"
# )
"
)
+$
(
"
2
"!
)
$ KF -# +

2
&

"

#
$
+ ") .Z

"0

+ .

""
# )

0
" + "
$ C" +"
&$
%"
.
2"

+
"

"

"

"

"2 "
" )

) $

tipos de interfaz$

" ")
)

" #

.
)

+
(

"

(
"

&

"

"-

. %
/
'

" O +
&
"

.
'/

public interface IOscilador


{
double Voltaje(double tiempo);
}

'IOscilador
" $ #
. % $
/

'
" +
"

"
)
)

/
(

) heredar 8 "
&/
System.Object,
"
)
System.Object$

"

heredar

implementar

"-

$
A+
" "

"
$
%(
2
+ "+ 2

$
& +

(
'

" (

"!
"
&
'$

implementar

"

"
"

&
(
. (

'$
.2

$ Implementar .
) . " "

4
"

"

'

& " 2

""-

"
+

"

'/

public class Triangular : Chip, IOscilador, IConfigurable


{
public double Voltaje(double tiempo)
{
// Implementacin de la onda triangular
}

IS

// Otros miembros
}

"
#

Voltaje$

#
"

Chip

"
&
)

)
(

IOscilador +

"
(

# "
+.
.
M
N
"
"
1$

L*
0) $
(
8.
"

$
"
"
/

"

"

" #
"! )

Triangular "
' IConfigurable/

&

.0
)
"

"
"-

Voltaje

) $
"(
"
8. (

"

" implementacin explcita/

&

double IOscilador.Voltaje(double tiempo)


{
// Implementacin de la onda triangular
}

")

")
# "

"-

"
"
+
%
")
." ( # +
(
"
" "
&
"

"-

(
#
"

")

.
.

%
")
"(
"-

(
.

"

' "
"-

"-

Triangular$

"

&

"
&. $

"!

"

" "
8.
"
")
2
'
2
C$
&

"

'

"

"

"
"

"
"-

(
"-

"
8 2

8
'4

(
2"

'

'
" "

"

&

public void Test()


{
double d = ((IOscilador)this).Voltaje(0.0);

I?

"!

public void Test()


{
// Cmo ejecutar el mtodo anterior aqu?
}

&

'

"

public class Triangular : Chip, IOscilador, IConfigurable


{
double IOscilador.Voltaje(double tiempo)
{
// Implementacin de la onda triangular
}

") "

8 2

2
"
$ &

"$

(
'(

"

") $

"

"
$

'/

8 2

)
(

"

"
3

"

& 8 2
(
"
(
"' "
I1 +I2 +(
")
(
C "
" M$ . "
" 2
"M
C " "
'$
(
(
" $
I1.M I2.M
& 8 2
"-

"

%$

07

Console.WriteLine(d);
}

Triangular

"
)
"

# #

"

"

#
.

" )
& .
Voltaje

"

(
.

"

' IOscilador$ *
&
(
1

'

&E
Triangular$

2
' "
.(

"

" %
. &$

&

"&

x = y;

"

"

F
F

/
y

' +(
' +(

"
4
"
implementar + derivar
8
&

'IDisposable
Ventana (
.

C
" $

"

"
"

"
$
"

) +

'IVentana (
& Claraboya$
IDisposable

)
" +

%"

'$
" " $
!

'&
& VentanaRedonda (

.
( " "

"
'

"

"

"

&"

"

%"
/

"

(
"

!)
"
"

"!
# ) %
.

'"
&
System.Object

'$

)
(

.
.
"

'
(

. "

"
")

"

"

# %
-$ "
+
.
$ 2
"
#
# /
% .3
. "
$
!
"0
$
" "
"
'$ " +
"
&
)
$
"!
(
"!
$
"
. &
) 8
!)
"
(
"
"

IU

El Conocimiento Secreto

"

!"

"
$

'

" #

&

" 3
)

% ( 2

"!

"

$
(

"
"

"

% ( 2

" %

' "

/ #+ .
5 )% 6 ) .
) ' 8 2 "

" ")

"

"

8 "
"

'

(
'

"-

&

(
'
$

5
1

G O 1

"
# +(
) %$ K1 ! .

"

1[

'

+
+

&
$ K*

"
)

"
) %

" #

'
4

*!

8
"

'

5
.
O

" "
%

!"
)%

.
" "
& 8. "

" + 8.
" %

"!

"

#" %

#+
"

" +
&

"
$ R
" "

"

')

" '
" )

)
2

+
) %

- "

$
"!
&

) $

"
"
/
)%
"
"!
)
$A
" )
.
%
"
Q ++
+
L .# 1 +
&
# )
#)%
"
+ +
ray tracer$

)%
"

"
)%

"
&
"

" "
&

(
"

"

"

&

"

!"

(
")

"

&
)
" "

4)

"
)%

$
"

$
(

"
#-

) "

$
"!

" '
) "
&
" #
) "
2 " /

estructuras$

$
K

( )

)%
)

"
$ *!
)%

"
)%

!"

(
"

.0

(
" "

.
"

" % .! "
$
$
"
'

(
" "
+
"

!"
8
"

G! "
"
# "
5 .6
#

. (

(
.

"
"
"

" "

"

$
'

. "/

public class PuntoC


{
public double X, Y, Z;
}

"

public struct PuntoS


{
public double X, Y, Z;
}

" .

"

"-

public static void Main()


{
PuntoC p1;
PuntoS p2;
}

Main

" "
)

%
" "
#

(
"-

"! "
$ "
# )
' $
+ ) "

)
"
'

.
"

" "

/
"

!
%

#
"

%
)+
" 3$
=; )+ /
"
"

8. (

"

&

I= )

'
"
" "

# )+

$
")

'

public static void Main()


{
PuntoC p1 = new PuntoC();
PuntoS p2 = new PuntoS();
}

")
"

) /

!
%

!"

;>

"
'

PuntoC

"

" "
+

)%

" "
(

"

"

p1$

)
"

"

")

$
'

& .

&

"

"

"

" "
'

"

.method private hidebysig static void Main(string[] args)


cil managed
{
.entrypoint
.maxstack 1
.locals init (
Estructuras.PuntoC oc1,
Estructuras.PuntoS os1)
newobj instance void Estructuras.PuntoC::.ctor()
stloc.0
ldloca.s os1
initobj Estructuras.PuntoS
}

&
"
"

%
&

$
&

"

%
)

&

'

" '
"
) 2" # )

'

) "
"

9Load Local
$ *! ( # )

"
&
inicializacin$

"

$
%
"
& "!
(
& .
.

. )

Address@
$
construccin

&
"

&

"
"
#
O

$
(
'"
"

&

O
)

" #

)
'

. %
"
& .

.
&
) ")

(
*

"

I= ) /

; PuntoC p1 = new PuntoC();


mov
ecx,969668h
call
FFCB0EAC
mov
edx,eax
; PuntoS p2 = new PuntoS();
lea
edi,[esp]
pxor
xmm0,xmm0
movq
mmword ptr [edi],xmm0
movq
mmword ptr [edi+8],xmm0
movq
mmword ptr [edi+10h],xmm0

"
8

+
"
" / )
'
+
(

"
"
.
E )

"

(
" "
4D
# "

"
8

.
$

& #

.
.

"

)
.

&
(
.
# )+ +
.
"
.
&
)

'

"
$

")
"-

"! "
.
" "
"

$
)

"
)

$
%

,
# .
"

"

PuntoC

"

)
" "
"! "
$

"

"
.
" "2 " +edx$

(
Main

PuntoS

"

(
"!
"-

( 2
$
# "
" "
.

"/

)) "
"
.
)

'
"

"
$

.
"
"

)
&

&

;:

K &"
" #
/

"
$

A +(
" +

"

Console.WriteLine(p2.X);

& . .
.
$
)% $ " . ( #
Main ( # "

""
"-

")
.
/

'

"
)%
8

"
"-

)
"

&
"

" "

private static void Imprimir(PuntoS p)


{
Console.WriteLine(p.X);
}

"-

"

.
.$

"

"
"

&

&

& .

Utilice estructuras para tipos de datos relativamente pequeos.

(
"
A + "!
"!

" #
"-

!"

"
$

'4

"

"

"

)
%

. "

"

"

%"

!"
!"
" 2
"

.(

"!

'

"

) .

" $

'

"
"

$
/

public struct Vector


{
private double x, y, z;
public double X { get { return x; } set { x = value; } }
public double Y { get { return y; } set { y = value; } }
public double Z { get { return z; } set { z = value; } }
}

" 2

. 2

"

"

8
"

&

' &
" 2 $

&

&

$
2"

"

"
)

!"
$

"

"-

) .
") $

& .
.

) %
(

$
"

' &$

// Esta estructura contiene errores de compilacin


public struct Contador
{

;=

- "

' todos
8.
.

"
"
&

private int valor;


public Contador(int v)
{
Limpiar(); // Esta llamada genera un error de compilacin
valor += v;
}
public void Limpiar()
{
valor = 0;
}
}

& .

"

'
)

"
& .
K
)

( -

"
Limpiar
%
( Limpiar
.
"
. "

/
valor$

"
(

( #+
4
& 8"

$
B

"

"

'& # +(

)
2"
"

!"
2"
"

"

&

" "

1/

)
) "

&$

PuntoC[] puntos1 = new PuntoC[128];


PuntoS[] puntos2 = new PuntoS[128];

")
"
(

"

'
2"

) $
# )- "

:=T
/ # )2"
%
:=T

"

"
) $
(
& .

(
!"

$
!)
' &

)3
-

"

# )

ValueType

(
"

System.Object$
( ValueType

"!

"!
"0

26

/
&

&

'

'

&

%&

") -

"

"

"

$
"! "

$
) %
2 "

&

"

&

"

# )

1
+

&

& .$

#
"

2
.

"
# ) 2(
" "
&
$
"

;I

"
"

" +)
"

" +0

&

)
"
/

$
+ &

" ")
" "
$

'
")

+
+
")

"

#
" ")

&

'

" ")
")
(
8

&
.

&

'

'

)
# $

& "

/K

( -

" ")

" "

/
" "
.
8

""-

$ KF #

ValueType/

public override bool Equals(object obj);


public override int GetHashCode();
public override string ToString();

Equals #

ValueType

)
Equals

" & (
"

"

"

"

GetHashCode$

+ .
'
8& +

&
"
3

"
$

&
%

"
Equals

)0 (

public struct Vector


{
private double x, y, z;
public double X { get { return x; } set { x = value; } }
public double Y { get { return y; } set { y = value; } }
public double Z { get { return z; } set { z = value; } }
public override bool Equals(object obj)
{
if (obj is Vector)
{
Vector v = (Vector)obj;
return x == v.x && y == v.y && z == v.z;
}
else
return false;
}
}

A +(
(

" #
8

(
'

;;

Equals$

"
%

(
(

&$

!"
!"

" '

(
"

"+

) "

"

"

" )"
# ) 2" " '

.
&
) .

&

"
(

Equals

"
" $

%)
# #
) "

2$

$
)

&

) %
"
"
#

!"
"

#
"

&
"
$

# "

(
GetHashCode

" "
"
&
2

Vector

& +

"
"

public override int GetHashCode()


{
return x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode();
}

"
xor$
")

"
.

&

& . hash
"
" $

")
(

"

"

,
&

hash

& 8
# ) 2)
!
(

$
(

) .

ToString$

"
+

) ) (
&/

"

public override string ToString()


{
return String.Format("V({0},{1},{2})", x, y, z);
}

0 "
"

"

(
.

Equals

"

public static bool operator ==(Vector v1, Vector v2)


{
return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
}
public static bool operator !=(Vector v1, Vector v2)
{
return v1.x != v2.x || v1.y != v2.y || v1.z != v2.z;
}

Vector

) 2"
2
)%

"
"

)0 (
$A

$
%

&

"

2"
"

(
- "
"

(
8
Equals

2
A "
K ) 2

(
"

"
&

"-

"-

2$ C
4 "
' ++ ) "
$

"
(

"
8 2 $
1
"
Vector

%"
"

"
"
" "
" /

"
""

"!
"

"

/
"-

'IFormattable

&
"

public struct Vector : IFormattable


{
public string ToString(
string format, IFormatProvider formatProvider)
{

;S

if (String.IsNullOrEmpty(format) ||
format == "G" || format == "g")
return String.Format(
formatProvider, "V({0},{1},{2})", x, y, z);
throw new FormatException(String.Format(
"Cadena de formato incorrecta: '{0}'.", format));
}
}

"

"

"
3

"
ToString "

"$

."

ToString

"
(

ToString

&
"

"-

!"
"

"
"

"

!"

!"
$

"

"
"
&

"

"

"
&

""IFormattable/

public override string ToString()


{
return this.ToString(null,
System.Globalization.CultureInfo.CurrentCulture);
}

) "

(
"
"

ToString

&
.

'

&
)
) +.
#

!"

'
"

"-

! %
" # "!

"

K( -

"!

"
$

"!
"

$ K &"
"
"(
"
%
$
#+
)
&$
"
)

IFormattable f = new Vector();


Console.WriteLine(f.ToString(
null, System.Globalization.CultureInfo.CurrentCulture);

%"

#+
)
"
$

"! .
' IFormattable$
DVector

&
2

)
(

2(
") .

E K &"

."
"

" "
6/ #

5
$

%
"

+
) " /

(
(
. 2"
& # )

) f

"
)

"
)

"
"-

'
"

# 2
"

'
) " /
)

"-

"

- "
&
#

" "
. "

%
"

&
&

)
boxing

IFormattable f = new Vector();

")

"

&

!"
%"

;?

boxing

"
" $

+
"

!"
.

&/

"
"

)
)

(
( #

"

)
"( .
'
8
#

& 5
#

) "

6
. "

"

boxing 3

)
)

"
'$

"

unboxing (

&
(

'

"

"-

# #'

%
.

Vector

"

&

Vector v = (Vector)f;

"

0 "

&
" .$

)*+,

boxing
$

( - "

.
boxing

%
8

(1
*

# )2 (
"

tem +
Object$
ValueType$
#

"

.
"
G
5
'4

7
#

)
/
6$

"
/
.

!
!"
. +
'
"!

"
(
&

(
. $

"!
" # "
"
(

"
&.

&

"

"

Common Type Sys-

. %$
. &
)

& +
$

+
Variant (
')
+ ") .
+
"
" #
. " &
)
(

"
"

3 "

"

boxing

&

. %
)
"!

"

# +
+

) "
$
3

& =$>
)
5 )%

"

. )
.

& "!
$

;U

El Conocimiento Secreto

!"

2 "
&

"
$

!"

" 3
)

." #

" "
'$

) "

"

"
"
(

"

.
"&

"
)

'
"-

$
(

"

(
!

'$
)

" "

"

)
(

# +(

"

$
"
&

(
+
" IEquatable<T>

)!

$*
"

#+

'8

"
(

#
"

& .

"
'

) " $K
+(
"! 8 2
(
(

IComparable<T>

.0
)
1

( - # .
(

) $
) %
"
. -

"

6
*

1*

variables

" " $

""

(
#2 / K ( - " "
(
"
( vara$
)
+
"
$
)
# #
"
(
M
)
)
&.

&
.

2
.

"

"
)

(
&.

" (

1 R

variables

"

$R
)

"

"
K

variables de funciones

"
)

&
&

. (

)
%"

$ " .

2"
.

" (

+(

"

"
"

" "

&

& 2
'
"
!"

"

public static double MediaRaiz(double[] puntos)


{
// Asumiremos que el vector puntos no est vaco.
double total = 0.0;
for (int i = 0; i < puntos.Length; i++)
total += Math.Sqrt(puntos[i]);
return total / puntos.Length;
}

KC

"

& 8

2"

"

" /

for (int i = 0; i < puntos.Length; i++)


total += Math.Exp(puntos[i]);

"
cualquier

(
%
&

&

variable de funcin/

"2 " K ( &


(
"
"
' $
.
&
"
&4(
)
!"
(
&
(
/

. "
%"
2" (
$A
.
5
(
)

& Media

"
#
"

( 2(
6
#

"
&$
)

)
"
. "

!"
/

") -

"

public static double MediaRaiz(double[] puntos,


TipoEspecialAunPorDeterminar funcion)
{
double total = 0.0;
for (int i = 0; i < puntos.Length; i++)
total += funcion(puntos[i]);
return total / puntos.Length;
}

4
)*+,

+ " "2 "

#
" 5

$"
*

"

! )

C
+"
F
C

! "
'

3
6$

&
C
GG
B "*

*
(

&

* *
&
*

I
A

'

"

"

"
)
. "

"

) "

"

public abstract class Promediador


{
protected abstract double Funcion(double valor);
public double Calcular(double[] puntos)
{
double total = 0.0;
for (int i = 0; i < puntos.Length; i++)
total += Funcion(puntos[i]);
return total / puntos.Length;
}
}

" . (
&

+
!(

'(

"

public class PromedioRaiz : Promediador


{
protected override double Funcion(double valor)
{
return Math.Sqrt(valor);
}
}

&E
(
"

2
'

'
&$

"! (
"
. "

#
"

"!
+
"

/
double[] puntos = new double[]{ 0.0, 1.0, 2.0 };
Promediador prom = new PromedioRaiz();
Console.WriteLine(prom.Calcular(puntos));

"2 "

'

. 2
2

"

&/

"

' (

'/

public interface IFuncion


{
double Funcion(double valor);
}

2"

. "
'

S>

&

"

TipoEspecialAunPorDeterminar/

&

. "
.
") -

&

public static double MediaRaiz(double[] puntos, IFuncion funcion)


{
double total = 0.0;
for (int i = 0; i < puntos.Length; i++)
total += funcion.Funcion(puntos[i]);
return total / puntos.Length;
}

2 (
2
& (

# )2 #

(
"
"

"

$
"

0
(
&

"
. "
#
"

'/
public class PromedioRaiz : IFuncion
{
public double Funcion(double valor)
{
return Math.Sqrt(valor);
}
}

"

"

"

")

" # /

double[] puntos = new double[]{ 0.0, 1.0, 2.0 };


IFuncion raizCuadrada = new PromedioRaiz();
Console.WriteLine(MediaRaiz(puntos, raizCuadrada));

& 5

public delegate double Funcion(double valor);


public static double MediaRaiz(double[] puntos, IFuncion funcion)
{
double total = 0.0;
for (int i = 0; i < puntos.Length; i++)
total += funcion(puntos[i]);
return total / puntos.Length;
}

"

2
"#
&"

7 "

&
(

)
.

Funcion (

"
)

(
" "

& +

" /

double[] puntos = new double[]{ 0.0, 1.0, 2.0 };


Console.WriteLine(prom.Calcular(puntos, new Funcion(Math.Sqrt)));

"

- "
O

"
F '!

$ K ( -#
) 2# )

"

"

2#

'

double[] puntos = new double[]{ 0.0, 1.0, 2.0 };


Funcion raizCuadrada = new Funcion(Math.Sqrt);
Console.WriteLine(MediaRaiz(puntos, raizCuadrada));

=$>

8 )

double[] puntos = new double[]{ 0.0, 1.0, 2.0 };


Console.WriteLine(prom.Calcular(puntos, Math.Sqrt));

(
+
8

2
&$

"! " .
( " %

Funcion
variables de funcin

)
Math.Sqrt D "

=$>

&/
"
"
(
"

(
!) "

constante de funcinE

")
"

%"
" % 8
)
"
+
$ C.
&
/

(
) "
!"
"

// A una variable entera le asignamos una constante entera

S:

int i = 0;
// A una variable de funcin le asignamos una constante de funcin
Funcion f = Math.Sqrt;

)
2
'

&
( 3 +"

&

& (

// A una variable real le asignamos el resultado de una funcin


Funcion f = Math.Sqrt(3.0);

&

")

&

&

"

&$

"
A
$

"

8
"!
)
#
"! "

&$
"
"

$
"

.
/
"
3
)%
. % $
)%
.

#+
. %
. %
.
"!

C # +"! "
"$
.
. + "

3
. %(

+
#

23
" (
"

"
&

$
"

"-

"

"

&

#
;$

"
&/K )

JJ (
/
.
"2
$
") "!

8
".
") 6
2
"
)%
"
) "

.
. %5
(

.
.

$
(

$
/
. " "

"

"

"

"

J
J

"

"
%

$
-

+
)%
.

"

.
& "!

&

"

(
. "

( 3

"
"

& "!
"

&

. + "
.
" +
B :$>
"
)

. "

.
$
. /

"

/$
# )2 (

"
'

Funcion raizCuadrada = new Funcion(Math.Sqrt);

.
"

& =$>

"

/
Funcion raizCuadrada = Math.Sqrt;

" (
Delegate
'
.0 " "
)
&
)
.
S=

MulticastDelegate (

.
")

"
Object$
.
"
+ ") )
(
#
" $

&
&

.
% ,

. "
$

&

"
") 8
"
"
) '
target
& "
(
.
"!
.
"
methodPtr
"# (
)
"
&
&$Q "
"
prev
.
'
" "
. $

" $
$
& .
(
KF 2
'

")
8

& (

)
(
" "

.
.0
&

$ . " +
$7 "
%"

$
"

.
."

"
.

"
) %"

"!

"
!
0 "

"-

public delegate void Mensaje();

.
"-

""

!"
"

"

+
"-

$
!

"

public static void BuenosDias()


{
Console.WriteLine("Buenos das");
}
public static void Adios()
{
Console.WriteLine("Adis");
}

"

) +

+"

Mensaje cadena = new Mensaje(BuenosDias) + new Mensaje(Adios);

"

"

'

&

%
/

"-

"-

"

Combine

Delegate$

.
"

$
#

cadena();

A "

"

")
!"

#+

& + # "
$

!"

0
+
" .

.
.
"

$
%
%

&
+

2
.

. )
" %
!"
$

/
(

"-

"

"
(

&/

bool HazAlgo(double d, ref string s, out int i);

.
"

#.

".

(
%

"
"-

!"
$

%"

$
/

delegate bool HazAlgoDelegate(double d, ref string s, out int i);

"
.

"!
/

HazAlgoDelegate "

"

"-

// Estos son mtodos automticamente declarados para HazAlgoDelegate


public IAsyncResult BeginInvoke(
double d, ref string s, out int i,
AsyncCallback callback, object state);
public bool EndInvoke(ref string s, out int i, IAsyncResult result);

SI

"
.

" )
"
" $

!"
.

"/

BeginInvoke

""! BeginInvoke "


AsyncCallback +
.
"7 "

.
#

!"

"

&" "

"-

BeginInvoke$

EndInvoke )
EndInvoke .

!"

IAsyncResult$

"
.

!"

"!"

"

$
+

IAsyncResult$

!"

"

"!

"

// Obtenemos un delegado que haga referencia al mtodo a llamar.


HazAlgoDelegate d = HazAlgo;
// Ejecutamos el mtodo BeginInvoke del delegado.
string s = "Valor inicial";
int i;
IAsyncResult result = d.BeginInvoke(3.14, ref s, out i, null, null);
// Ejecutamos algo mientras BeginInvoke termina.
OperacionAburrida();
// Ejecutamos EndInvoke para esperar por BeginInvoke
// y obtener los resultados.
bool b = d.EndInvoke(ref s, out i, result);

BeginInvoke

"

$
.

%
"
"

"2
$
. + )
+
"
2
# )
.
#
0
HazAlgo "

&
$

"-

EndInvoke ) (

# "
"A+
(

#
"
%"

$
(

"
"
!%
!"

"
#
# "

( HazAlgo # +
%
& .$
+

EndInvoke$

##

HazAlgo

&

&

#+

%"
"

'
#

"
"

/
// Otra forma de esperar por EndInvoke.
while (!result.Completed)
{
result.AsyncWaitHandle.WaitOne(1000, false);
OperacionNoMuyLarga();
}
// De todos modos, es necesario llamar a EndInvoke.
bool b = d.EndInvoke(ref s, out i, result);

IAsyncResult (
#
BeginInvoke$
% & 2
#
"
$*
#+
# #
" "
"WaitOne )
AsyncWaitHandle
BeginInvoke$
") (
# (
" #
(
#
2
"
%
"4
.
"
"
!"
+
(
" .
$
"
.
'+
+
# "
%
.
"
" %$ )
( siempre
# +(
"
EndInvoke 8
!"
$

# "

'

Completed

KF -# 2"
%

'
+(

(
2"
% &
"

)
BeginInvoke

# $1

&

% &
"-

( BeginInvoke
. /

public delegate void AsyncCallback(IAsyncResult ar);

S;

"-

2
(
!"

"

2"

"-

&

private void EjecucionTerminada(IAsyncResult ar)


{
string s = "";
int i;
bool b = ((HazAlgoDelegate)ar.AsyncDelegate).EndInvoke(
ref s, out i, ar);
}

%"
%
"
Q

)
"

( '! "!
& 2
$
.
.
&

"

"-

" .
&

!"

IAsyncResult$

"

!"

'

BeginInvoke/

// Obtenemos un delegado que haga referencia al mtodo a llamar.


HazAlgoDelegate d = HazAlgo;
// Ejecutamos el mtodo BeginInvoke del delegado.
string s = "Valor inicial";
int i;
IAsyncResult result = d.BeginInvoke(3.14, ref s, out i,
EjecucionTerminada, null);
// Podemos seguir a nuestro aire

%
EndInvoke

&

HazAlgo

"

!EjecucionTerminada +

" !

'$

SS

7
$ CO 7

"

5 "

$ O
"

&

)%
") .
(

"
6 K ( -O

"

&
&

"
.
2(
" 3!
+
$ KA
.
S>
2 !
+
"
2
+
2
)
" . & .!
)
$
"
8&
"
$
"

N
$

' ,

"! 8
$ KF - .

" +
$

'
'&

%
' &
2!

%)

"

3
"

Hashtable$ K

Hashtable

" "

"

)
"

IComponent

" !
(
'

(
&

$
$

"

'

. %

3
' $

(
"
%"

System.ComponentModel +
Component "
$
'IComponent

")

"
"

"

'
"
2
/

public interface IComponent : IDisposable


{
ISite Site { get; set; }
event EventHandler Disposed;
}

"

Site$

"

"

8. (

"

3 (
&

"
$

"
3$

# .

K &"
(

"

"
"

5 )

3
+

"
$ Q "
$

" &

"

"

. "

(
"

"
.
) & )
) &
.

/ K ( $K ( (
)

"
9 $?T@+(
(

"

$
(

"

"-

+
!

' !
"

"

+ #

%
"
%"
"

)
+

'
) %
"
6"
$
Text
) &
")
3$
) %
! "
"
# ) 2(

"
. "

"
"
%

"
"
"!

"

"-

'

"

!
(
34
O
(

) &$
"!

"-

' &

"

"

"
$

$
(

componente

"

"
$

'
&
"

(
(

"
. "
" # "!
. %(

3
8
"
+

"

"

"

" "
&
&
2 " #

2$
&

"!

"-

(
"-

"

"

%"

private int edad;


public int Edad
{
get { return edad; }
set { edad = value; }
}

"
"
"(
"

#
)

!"

$
#

"

"-

!"
$

"" "
)

$
" "
)

(
$

(
)

'

"

+ )

"

.
"-

"
/

public int Edad


{
get { return edad; }
set
{
if (value < 0)
throw new Exception("Edad incorrecta.");
edad = value;
}
}

(
8

"

"

&

'

&$
'

"

.
"

"

&
#

"

"
'

+
"

private DateTime fechaNacimiento;


public int Edad
{
get
{
DateTime hoy = DateTime.Today;
if (hoy.DayOfYear >= fechaNacimiento.DayOfYear)
return hoy.Year - fechaNacimiento.Year;
else

SU

return hoy.Year - fechaNacimiento.Year - 1;


}
}

" "

# +(
&

. "
. "
(
" $

.
&$

.
!"

" " #

&
.

!"
!

"$

(
$

"
) $
$
%"

&

")

"-

"

(
&

"

:$>+:$:
(

"

")

"

Edad

) "
/

2
)

=$>

"

" "

public int NombreCompleto


{
get { }
internal set { }
}

(
"
")
(

"" "

")

$
&

)
$

indexador

"
'

indexer

" +
9arrays@$ " .

(
# )

"

"
+(

"
)

&/

c[0]

"
."
)
. %
. %
JJ A ) 2 (
") (
)
.
.
B

JJ

"
"!
."

2
"
JJ$

"
"+ 2
%"

"
.

$ KC

"
"

8
"! )

%"
(

%"

+
'

(
)
$
"
# $

#+

public class Vector


{

(
"!

8
(
(

"
.

referen-

".

" '
%"
.

$A -

+
&
"

"
/

)
+-

! )

"
8

)
.

&

7"

ST
-

&

"
&$
$
+
!)

"
.0

JJ &

cia

."

$ KF -

[]$

JJ$

)
)
"!

(
"
/
"

private double x, y, z;
public double X { get { return x; } set { x = value; } }
public double Y { get { return y; } set { y = value; } }
public double Z { get { return z; } set { z = value; } }
}

" #
$

)2
v[1]$

. "
' v.X
2"

"! &"
2"
. "

v[0]

"
+

"
'

v.Y

Vector/

public double this[int index]


{
get
{
switch (index)
{
case 0: return x;
case 1: return y;
case 2: return z;
}
throw new ArgumentOutOfRangeException("Indice incorrecto");
}
set
{
switch (index)
{
case 0: x = value; return;
case 1: y = value; return;
case 2: z = value; return;
}
throw new ArgumentOutOfRangeException("Indice incorrecto");
}
}

"

")

"

)
.

)
!"

"

$
!"

"
"$ "-

%"
&

"

!"

8
)

"

."
+

)
" "
!"

!"
(

#+

"
"
" "

""-

"

(
$ ")

#
+ "#
+

"

. (
"

( /

8
$
8

+
"

$
.

") .

&$
%

"

DataRow (

%"
$

!"

public object this[DataColumn column] { get; set; }


public object this[int columnIndex]
{ get; set; }
public object this[string columnName] { get; set; }

"

!"

&

"

public object this[DataColumn column, DataRowVersion version] { get; }


public object this[int columnIndex,
DataRowVersion version] { get; }
public object this[string columnName, DataRowVersion version] { get; }

. SV

Common Language Runtime


B$

*
"

"
"
."
)*+,

"
(

$ 7G$

Item +

"

")

"
) .
")
(
"
&$
+

$
I# 3
" "
&
!
"
+
+ "
"
#

"

8
8

" 4+
"
(
8
" $

( 3
"!
"
"
"
" $
#

")
2

DataRow

"

."

" 2 $
6/ ) "

"+
(

"

"+ 2
.

'< ; E
*
!
Item

"! )

"

"

"

"

"
$
!
"

public struct Vector


{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}

"

"

"
&

"" "

"

"

(
"-

"

"

"

")
(
/

"

)
$

"

")
$

"-

$
2"

-"

"

public double X { get; private set; }

" "
&
(
+
"! "
&
"
) "
'

'

") .

" %
#
'

) $

" "
"
" )

"-

(
$

"
2

' &

"

Vector (

"!

$
)

(
(
& .

2
"

# "

"

/
"
" &$
" %" $

"
) "
."
.

// ERROR: el compilador se quejar porque Vector es una estructura.


public Vector(double x, double y, double z)
{
this.X = x;
this.Y = y;
this.Z = z;
}

.
. &
- 8 2 "

?>

'

8.

(
"

"-

"
"

.
"

&

"!
2

"

"
#+

& .$

"/

public Vector(double x, double y, double z) : this()


{
this.X = x;
this.Y = y;
this.Z = z;
}

"

" 2
$

'
.

) "

.
"

&

(
2 "

( -*

"&

"

(
$C #
&

2"
$* #

"
.
( -

"

&

.
eventos

" ")

. "
)

# #

$
" ")
'

% ") - (

"
. $
2
"

" Button
.

suscripcin

"-

")

"

/
.

#
"

Button

Click$

#
"

"

'$

Click$

8"

&

" #
.

"

System/

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

!"

2"

)
)

.
"
" " $
#

+
"

)
.

"

"

)
!"

(
)

"

EventArgs

EventHandler/

public class Clase01


{
private EventHandler campo;
public EventHandler Propiedad
{
get { return campo; }
set { campo = value; }
}
public event EventHandler Evento;
}

"
"
&

(
+ %"
"

8 2
+

$
$

8.
(

"
") . ,

"

"
"

"
.(

'
"

& "
"
"

&

&$
"

"

"
"

?:

public class Clase02


{
private void ManejadorCompatible(object sender, EventArgs e)
{
System.Console.WriteLine("yoo-hoo!");
}
public void Prueba(Clase01 cls01)
{
// Usemos la propiedad
cls01.Propiedad = new EventHandler(ManejadorCompatible);
// Usemos el evento
cls01.Evento += new EventHandler(ManejadorCompatible);
// Esto produce un error de compilacin!
cls01.Evento = new EventHandler(ManejadorCompatible);
}
}

"

.
"
"
$
)
. & + " +
. (
") "
. & +
/

.
)

"
(

"

5(

$
3

"

"

" .

// Sera tambin correcto!


cls01.Evento -= new EventHandler(ManejadorCompatible);

"
%
."
.

"

!
"

8
(

(
.

. "
#

"
/

+
.
+ 8
.

"

"

A
" #
"
N # " %
"
)
" # "!
$
"
" "
!"
%
$
"
(
# )2 "
.
. %
"
"
"

2
. " &$
A + B$
"
A$
"
/

"
3
"!
$

"
$
%

"

.
(
") +

"

(
+&

"

&$

&
X M #$
$
N +
" "
" %"
"
/
) .)
3
" "!(
(
3 . &
'!
+ # )2
$
" "
&
%"
!
"
A "
5 ! 6
2"

"

B +

"
'

"

3 U>
" )

.&
.(

$
(

#
N

&

"
") "

{ Esto es Pascal }
procedure B; forward;
procedure A;
begin
end;
procedure B;
begin
end;

"!
?=

& (
$

"

"
" ! "

& (
"-

) 2"

"B$
( "
# N

"+ 2

'

2
"

& (
-

U> $

" "

"+ 2
&
"
!
!

.
$
tracta

"
+
"

$
)
#
"

"
8
&
& .
$ #
)
#
! 9 (
)
@/

"
"
"

&

)%
$
#

0 "
" '!"

" " (
$

. % "
"

"
" "
"

..

"

)
!"

rbol de Sintaxis Abs-

$
"
& .

)2
"

."

"
+

=$>/
clases parciales$
)
" "
#
&
$
.
" "
# $
%"

public partial class A


{
public A() { }
public int Valor
{
get { return valor; }
set { valor = value; }
}
}
public class B
{
}
public partial class A
{
private int valor;
}

A#

."
(

"

(
$

"

'
& #
)
+
" "

2
0)

&
"

."

A #

."

&
" (

+ ")
&$
."

"

"
"

)
) "

(
)

'
/

"
!
$
$

' $
A#

%"
'$

."

System.Object +
" "
'IDisposable 9 $?V@/

"
"

public partial class A : IDisposable


{
public A() { }
}
partial class A
{
public void Dispose()
{
}
}

2"
%"

# )

"
"

&
"
&

'
&

")
$

."
"!

'#

" "
"
?I

"

&

"

"!

."

"

" "

7
)

+ "
.
" . "
=>>I/

Form1.cs (

& . .
" "
#
"

"
.

Form1.cs

& .

"

"

"

)2
-

#
" +#
" . "

#
$

"
"

Form1

8
+

"

)
#

Form1.cs

"

'

)
2
/

public partial class Form1: Form


{
}

?;

"

#
'
(

& cs$
#
$

Form1.Designer.cs

partial class Form1


{

Form1

$
"

"
B

'
#

"

&

"
& .
" . $

resx

#
#

.
#

=>>S
"! "
. "

8
& resx
& . .
" "
# 4
7
=>>S/

.0 "
"

."

& =>>I 7
%
& .$
7

&

."

/
7
) "
$

& . )

)
(

"

" "

' &

#+
' &
"

'

+
"

$
."
"

"

"

"

."
$

%"

// "Nuestro" fragmento
public partial class A
{
}
// Fragmento administrado por Visual Studio.
partial class A
{
private int i;
public A()
{
this.i = 1111;
}
}

- "
2"
"
)
$

"

(
%"

&

8
" "

& I
6
# +(

&

" + "
"
&

' &
' &
"
'
"

"
# ) 2" +

+
'

$
) " $

"

.
"
"-

"

"

."

'

%
/ .
"

&

"

mtodos parciales$

) " /
' &
(
" # "+ $
"
"
.

)
"!
$
."

") "

"

&

."
"-

&
)

&
."
&

"

"
" " "- $
."
/

// Fragmento administrado por Visual Studio.


partial class A
{
partial void OnCreate();
public event EventHandler Evento;
public A()
{
OnCreate();
}
}
// "Nuestro" fragmento
public partial class A
{
private void Respuesta(object sender, EventArgs e)
{
}
partial void OnCreate()
{

?S

this.Evento += Respuesta;
}
}

%"
OnCreate

"

"
+

anuncia

."

+
# "-

$K

"9K

( - @$

%"

OnCreate +

$
"
"
(

"

"

"

.
2 & .
"
/
.
."
. #
" %
2
.
'

$
"
& .
.

??

# "
' & (

"
'$

"."

OnCreate

"

!
)

)
8

OnCreate

/
"

%
"" "
$

&
"-

OnCreate

+
!

" (
(

"+

8
*\
$
+ "!(
O
8
9garbage collector@
&
" '
)
&
" " $
. " )!
8
#
" #2 "
" $
generation scavengT>
%
.
"
"
"
ing )
.
( " %
"
% &
. " + #
"!
!
'
') $
T> +
V>
. %
'&
$
)
. %
)% " + "
+ .
(
)
" %
"!
" "
)
$
O
"
. %
" $
#
8
"
3 +
$
1

1[

"
"
)
$
"
"

#
(
&

+ %
%
" "
"
$

"

)
# +(
.

"

(
)
)

(
G X + # )

#
"!

&

" 4+ .
%.
) .
.
+
8 3
%
&
(
)
"
" 8
"
$

$
")

&
.

.
"

$
3

] $

2
/

Si nadie te ve no existes

"! 8 "
&
!"
% & (
)
&

/
+
!

)%
)
" "
(
!
.!"

( "
(

"

8
" "

%
)%

vivos

)%

'
4K
+( (
" /

)%
! #
"

(
-

)%

"

M #
!"
"
"

races$

races$

" "
'
(
" "

. "
)
)

&
"

"

"
"

"
+ "+

&

& %
)%

raz$

)%

)%

") - vivos$
)

$
.

+
&

)%
!

2
$

"
" "
") -

(
2
"
+
"

K
% "

.
.+ )
$ A
) %
" #
. % " )
$
( 3
)%
# "
"
2
"
" & )

/+

"
$
(
")

"
"

)
&
)

-"
)

.
$ "
8 " $

"!

"'

"

"

$
%
!

&
% &

"

.
.

"

&

. +
)% $

" +
-

"!

G%

. "

!
&

JJ/
Object creation is resource allocation

"
/
"
" (
(

/
6 .
& 8 2

&
5
)
)%

)%
6

#
)
"+ 2

"!
$ "
)%

) "
(

) "
"
(

4 +
( 2
"!
)
!
) & .
8

6$
8%
&$

8 2

) "

"
'

&
4+

) %

#
" " $
"
) "! #
$
" "
") ( # + " # #
) %
+
"
&
&
&

&

"
2"
"

" '"
"
"
"
(
%

"

"!
)% (
)
(
"+ 2
"! ) %
"$

'

"

"!
(
. "
" (

"+

&

. 2

) "

(
5

"
&

&

$
"

&

K
"

(
!
$

! .
(

"

4
&
'

(
)

" "
B

)
(

8
)

"
.

)%

#
"

" %

/
"
$

JJ/

public class ClaseConRecurso


{
private Recurso recurso;
ClaseConRecurso()
{
// Este es el constructor
}
ClaseConRecurso()
{
// Parece un destructor, pero es un finalizador
if (recurso != null)
recurso.Liberar();
}
}

."
" #
2
"
) "

Recurso$

Stream D

"

?T
-

.
) "
( -" "

%"

& .,

" ' # +(
1 " File( -$
"
"
/

Recurso

' &E
. 8
' &$ C # " "
%
$
.
.

,#

)
'

#
.

'

& .
& .

%
" +

# #

' &
"
' &

" #
' "5 " 6
+ )
)
&/ " +!
"
"# "
"
3
"
&
"! )
/ " "
) "
. &
"!
"
8 '
"
#+
&

"
"
")
Dispose$ *! 0

"
)

' & +
$

" ")

"!8"
"
$

$
&

)
") .

) $

" '
. "
$

"

) " $
" $
&
"
$
'
% (
")
& $
%(
" (
" "
'IDisposable/

"

" "
)

public interface IDisposable


{
void Dispose();
}

"
(

(
) " .

"
) 2

"
'

% &
. "

"
"&

IDisposable
Dispose$ #
)

"

) "

'
(
&

"

/
ClaseConRecurso objeto = new ClaseConRecurso();
try
{
// Aqu usamos la instancia creada
}
finally
{
IDisposable d = objeto as IDisposable;
if (d != null) d.Dispose();
}

&
"
# +" #
"
)

&<
.

)
.
"
!

#
3

& .
.
'(
%
(
" "
$
(

&

8
& .
"

.
!
#. $
" "
"
( #

.
(

( 3

"
&$

.
)
&

$
2

. " " %
&

.)
%/

+#

using (ClaseConRecurso objeto = new ClaseConRecurso())


{
// Aqu usamos la instancia creada
}

2
"
(

" "
&

#
& (

) % (
"
)%

'2

$
&

"

"
)

IDisposable/

using (SqlDataReader rd = sqlCommand.ExecuteReader())


while (rd.Read())
Console.WriteLine(rd[0]);

"
( #

%"
"

%
)%

&
)

%
(
. ?V

"
zombie
)*+,

&
#+

$
" $

2
)

)%

SqlDataReader
$)# !( 11 $
)%L
E
E
M0 &
&

Dispose

4
(

" "

&

"
. &
"!
( $
'
" + ) ) (

&

)% (
" "
&
)

*<

"!

)%
*J

)
)

) "

"

.0
"

"

"

garbage collection$

") . (
)
&
" "
" # "! .
)
) (
)
&
)
$
" 0 "
.
"
"

" "

&
"

$
!"

) "
%

$
.

"
'(

"

&

"
$7

"

) "

&

"!

" "

)
%"

/
public class ClaseConRecurso
{
private Recurso recurso;
ClaseConRecurso()
{
// Este es el constructor
//
}
ClaseConRecurso()
{
// Este es el finalizador
}
}

( "

"

"

"

"

"

Recurso$
" File-

)
(

Stream/
private FileStream recurso;

/K

"

'

ClaseConRecurso()
{
if (recurso != null)
recurso.Dispose();
}

/D

(
)%
K# ) 2 .
"

U>

E1'

" /K ( ! %
ClaseConRecurso # "
(
" ) $
)%
. #
recurso
"!
) )
(

'

1
" )
(

,#

"

# #

@$

recurso D
( FileStream

#
# #

'

! E9

" +

)%

"

)%
"

&
$

'

FileStream

$
#
recurso ! ") ' &
$ K ! )% 8 " ! "
ClaseConRecurso
"
)
) E
"!
) ) (
#
.
!
. (
" "
&
)
/
"
" "
!" $ D
(
.
'(
#
"

(
(

"
(

)%
)%
$

"
"

) "
+ )

"
"

) "
" Application$

&
"
)%
2

Application

$
"

&

" " +

)%

'
"

"!

"
.
)%
'
Idle

#
. ahE

)
#
) " "!
+
(
&
&
"
ThreadException$

+3
.

"

N
N

t0

. " "
"
)%
2
"
. "
"
)%
"
(
.

"

t2

"

" $

"

)
)
$

"
&

"

t1

) "
&
2$

+ %
#
)%
)%

"
.

%
.

lnea del tiempo

)%
$A+
)%
2
" $
.
)%
. $
0 "
Dispose
"
"" %
$ "
)% (
)2 # ) "
.
&$
.
(
"
Dispose
)%
#

U:

9
G

R[

"
4

"!

1 G O

(
!" . +
" %

+ . "!
"
) %

)0 (

"

"

'
+ 2#

#
!

"
#
"
#

+
&
%
"

"
"

+
JJ

. - $
" #
. - $
)
$

#
3
(
)
"

"

)%

)
2
8. (

. % (
"
"

'
. (
" $

"

% &
' "
3

#
1

"

' + .
JJ
'

"

+
"
"

.
JJ (
plantillas$
"

$* #
) "
"
) " $
GO
"
. #+(

" "
"!(
$
& . .

&

"

"!
#
&

%
!

" $
(

"

"

%+

.
$

"!
"

&
. -

&
"
(

. (

"

" .
'& .

templates

")
) " /

"
. JJ .
"
/
" "
&
.
&
) .
+
"
"
% &$
"

"

) %

"
&

. %
$

" #
!

") .
- "

. "

tipos genricos +

) "
$
"

"

) %

" +

"
& )

"2 " $
B
(

&

sui generis

"

+
"

# +O
+
2" (

%
) %
. %
. %

)
+
"
"
. -

O
"
"
.

"
$

"

"
8 "

. %

"
$
"

&

!
8& $
/

& . "!

$
)

'

"!$

"
.2/ " " cliente
.
+ " "
" "
"
+
# )
.
/

.!"

"

. . - $
)
&
0
8

" +

) )

& . (
& . (
. - $

. -

"

. proveedor

" $
) ) (

'
(

. -

. "
" #
' %"

9
2

. " &
8 " $
&"

"

"

@$

)% /
") - "
. - /

public class Pila<T>


{
private T[] elementos;
private int cantidad;
public Pila(int capacidad)
{
this.cantidad = 0;
this.elementos = new T[capacidad];
}
public void Aadir(T valor)
{
elementos[cantidad++] = valor;
}
public T Extraer()
{
return elementos[--cantidad];
}
public bool EstaVacia
{
get
{
return cantidad == 0;
}
}
}

Pila # "

!"

& #
' "
'"
" "

#
(
"

"
$
Pila

/
. "

!"

"
!"
T$
"
8
&

"

& + # "
$
"

T$
T

"
T

"
!

8
"

"!

!"

$
T/

Pila<int> p = new Pila<int>(128);


p.Aadir(1000); p.Aadir(2000); p.Aadir(3000);
Console.WriteLine(p.Extraer());

"

" .
)
#

"
"

# 5 "!

&

6
$

. -

%"

) $
(
(

"
2

#
!"

Pila

.
&

UI

public class Compilador<TipoNodo>


{
private Pila<TipoNodo> pila;
}

"
!"

")

!"

# "

!"
'"

TipoNodo 9D

"
E@

"!
(

"
$
"

(
"
'

Pila$

. -

5
" "
"

"2 "
"

$K
$

"
"
. - $
!"
$
"
"
"
&
"

Equals (

"

"2 "

&
8%" (
& $ KF - .
5
"
"&

"
(

"

"0

"! %
.
%"
(
$
$
. .
.
$
$
&$
. "

$K

"

8.
"

.
!
"2 "
"

(
2"

" "
&

.
(

"&

"

Pila &

"

(
"

(
.

'

'

!
)

Pila/

public class Pila<T> where T : IComparable


{
}

IComparable

2
/

public interface IComparable


{
int CompareTo(object obj);
}

CompareTo

""
)%
.

%.

"
"

)%
"
3

+ )
"+ +
")
"( %
.
"/

.
)%

"
)%
.
$
8
&$

public T Menor()
{
if (cantidad == 0)
throw new Exception("Pila vaca!");
T menor = elementos[0];
for (int i = 1; i < cantidad; i++)
if (elementos[i].CompareTo(menor) < 0)
menor = elementos[i];
return menor;
}

(
"
"

"

System.Int32

'$

U;

) " (
(
(
"
<$
" (
"
#
' "
"
" "
IComparable$
&.
+ .

!IComparable
" 8 2 "
CompareTo$ KF (
.
$
%"
"
2"
( " "
"

2 Menor '
%
2$

5"

6
"

" %

!"

"
+

"
.

"
"

# +"!/

&$

&$
CompareTo

"-

(
2 "

' / boxingE C +
4

".

ICompare

"
%"
) "

'#

"
)% $ K &"
boxing

'. -

)
#
!"
" ) $C
2" (
&
(
)

&
"
&

& :$:

=$> 8

IComparable

(
1
"

.
(

"

"

. /

public interface IComparable<T>


{
int CompareTo(T obj);
}

"

&" "

"

&

&

public class Pila<T> where T : IComparable<T>


{
}

'
!

"
"

#+

.
"

!"

%"

public struct Int32 : IComparable, IFormattable, IConvertible,


IComparable<int>, IEquatable<int>
{
}

IComparable

.
)*+,

)-

& . %

"
"!

" #

!(
*

&
"!

"

*
'
IComparable IComparable<T>

Menor

C
"

:$:

" "! "

&$

2"

8. (

!"

"

'/

public class Pila<T> where T : IComparable, Comparable<T>

2"

") - (

public class Pila<T> where T : TipoBase

"
" #
%
!
!
!

TipoBase

"

'
(
?
(
? &
(
?
!

!"
!"
!"
"

(
/
)
)
)

$
$
0)

"

!"

0 "
0)

!"

US

"
"
(

.
")
+ 8
#
$
"!
. " mtodos genricos$
/ ". "
2(
. - $
."
(
M
N Q " (
'
. - $
! "
2
""
.

"
(
&

" #
. "

(
$
. "

public static void VaciarPila<T>(Pila<X> pila) where X : IComparable<X>


{
while (!pila.EstaVacia)
pila.Extraer();
}

Pila<T>

" %
2(
" #
#
/

"

"
$

Vaciar 9

"
"-

Pila@
$

"

"

Pila<int> p = new Pila<int>(128);


p. Aadir(1000); p.Aadir(2000); p.Aadir(3000);
VaciarPila<int>(p);

") .

"

"

") -

VaciarPila(p);

"
)

"
(

# +(

inferencia de tipos/

"

!"

!"
"- $

. -

$
"
"

"
.

'(

"

( )
. %
(
. % 2
"
%

' +

. ( 3 . (
"
' '
"
8
"
$A +
"
& " . ) /
0 "
-

&
")
Min (

8
' -

#
)
(

+
)

"

".
)

"
&"
%"
#
-

"

$
B$

$ 8
"

System$

"2 "

! Math
""
$ & "
-

.
" "

/
public static decimal Min(decimal d1, decimal d2);
public static long Min(long l1, long l2);

."
" $
(

(
2

.
"! (
"-

# )
) ) (
. - /

)
Math

"
0

&
"-

public static T Min<T>(T v1, T v2) where T: IComparable<T>


{
if (v1.CompareTo(v2) <= 0)
return v1;
else
return v2;
}

U?

"

Min

."

"

'

"

// No olvide que Math no contiene mtodos genricos!


Console.WriteLine(Math.Min(1, -1));

-"

" "
8
" &
& $
."
/
"
."
"
"
."
". - Min<T>
T
$
.
."
"
" " $* ' "
"
8
.
#
$
# +$ " ) "
"
"
&
)
. / " #+ 0
"8
"
$
."

%"

. "

"!

"

.
"

)
+
.
"

# "

// La inferencia de tipos falla en ejemplos como ste:


Console.WriteLine(Math.Min(1.0, -1));

"
%"
."

$
.

( %2+
'&
"
."
8.
+
)
.
8
"
&
.
" - $
)

"
$
&
(

&
( T
"
& " 2

"

&
K" .
. "
2

. % ") 2(
(
"! "
( (

"

2
"

/
// Esta es la nica salida:
Console.WriteLine(Math.Min<double>(1.0, -1));

%"

.
+

"-

"

!"

. -

. -

Array

%"

public static int IndexOf<T>(T[] array, T value);

."

'

"

"-

int[] vector = new int[] { 1, 2, 3, 4 };


Console.WriteLine(Array.IndexOf(vector, 1));

(
$
"

%"
(
# +(

.
!"
)
(
" "
&
. "
unificacin

"
%

(
-

.
$

)
"

4
8

&
!"
" naked constraint

.2

"-"
& .

. -

. 8 3

restriccin desnuda$

!"
&

. -

"
(
" "

(
!"
T$

class MiClase<T, U>


where U: T

)
(
8&
. - $
%"
'$ *!
.
0
)
( 7 " /
) (
"
!"
'
" #
(
.
"
"
"
"
!"
4K
&
"&

)
" "

"
. "

"

(
& +
!"
$

$
"

)
'

( ."
&

'$
(
(
.

UU

.2

. %

. '

"-

. . -

%"
.

"

' asignaciones covariantes


& ./

"

"
0

"
."

string[] strArray = new string[] { "Haba", "una", "vez" };


object[] objArray = strArray;
foreach (object obj in objArray)
Console.WriteLine(obj);

)
)%

.
$ *!
.
"
( )

&/
"

"

) "

string[] strArray = new string[] { "Haba", "una", "vez" };


object[] objArray = strArray;
// Esto no debera permitirse
objArray[0] = new Buttton();
// para evitar desastres como el siguiente!
Console.WriteLine(strArray[0].Length);

&
") . K
& 1
(
(
%
"
"
$

"
A+

. %

)*+,

Length

&
)% (

(
"!

!")
"

"

3
$
%

.
"

&

&
2(

"

/# "
(

'&

"

"

!
")
.
"

&
&

) "
"
.
$

)%
debera
) 2 # '
& )! "
local$
"
. 2
%
/
$

"

8
1
!"

$
&
&

"

*
.

&
"

&$

&

/
D
9
4

2 "!

#)
"!
" "

"
.

)
1
& " +

'

"

C
D
(

"

" .
.

2
(

&

"

$
)
. -

- "

. -

$ "

List<string> strList = new List<string>(


new string[] { "Haba", "una", "vez" });
// Esto no se permite!
List<object> objList = strList;

(
(

. &
1
"

)
4+
"
"

UT
-

69

"

" @
" )

#2
)$

"

$
. "
" %
"
( '!
2"
"
&
2"

"

& / K( )%

"
" "

"

&
"

%
+

"

2
"

&

& .

restricciones desnudas (

0
."

"

$C

!) "

( 2
&$

& ./
public static class CovariantConverter
{
public static List<T> Convert<S, T>(List<S> source)
where S: T
{
List<T> result = new List<T>(source.Count);
foreach (S value in source)
result.Add(value);
return result;
}
}

!
"
"

$
")
)
"

CovariantConverter

$
!"

$K
$
+

$
.

"-

Convert

. -

"
)

.
(

( -

3 "

"-

.
&

"
&

&

!"

!
"

. -

"

"

Add

"2

"

"

List<string> strList = new List<string>(


new string[] { "Haba", "una", "vez" });
List<object> objList =
CovariantConverter.Convert<string, object>(strList);

"
"-

"

Convert$

"

)*+,

'(

"
"

&$
The C# Programming Language
7=
#

'< 7
O

."

&

'

5
"
%
. +
"
#
$$

.
(

!
."

" # "!

'
# # # )
"!

+
"

"! "
+

"
"

"
. -

$
. . -

%"
."

public class Dictionary<TKey,TValue> :


IDictionary<TKey,TValue>,
ICollection<KeyValuePair<TKey,TValue>>,
IEnumerable<KeyValuePair<TKey,TValue>>,
IDictionary, ICollection, IEnumerable,
ISerializable, IDeserializationCallback

.
( .)

") "

%(
!)
(

"
$ A

"
2

"

"
$ KF -

"
"
"

&
"
"

&
"

"

Dictionary

.
!) )
/

&
!"

. -

&
. -

"!

"
+

. UV

%
"

!)

"

# )
!)

Node

"

$7"
) ' "

BinaryTree/

namespace IntSight.DataStructures
{
public class BinaryTree<T> where T : IComparable<T>
{
protected class Node
{
}
}
}

!)
")

")

"

2/

IntSight.DataStructures.BinaryTree[T]
IntSight.DataStructures.BinaryTree[T].Node

)
(
) 5#
"
$
Node$

5#
6

%"

. -

!"

$
(

" &
"

!"
8

" +

!"

"
. -

. -

"

Common Language Runtime

B$

2/

IntSight.DataStructures.BinaryTree`1
IntSight.DataStructures.BinaryTree`1+Node

( 2
3

+
")

"
")

"

"

"

"
.
0"
" "
.
$

Node

&

. - /
!"
. ")

")
$
'

protected class Node


{
public T value;
public Node left;
public Node right;
public Node(T value)
{
this.value = value;
}
public Node Contains(T value)
{
int result = value.CompareTo(this.value);
if (result == 0)
return this;
else if (result < 0)
return left == null ? null : left.Contains(value);
else
return right == null ? null : right.Contains(value);
}
}

0)
"

-T>

$A

# +(

8
"

"
(

"
#

!"

!)

'(

public Node left;


public Node right;

!"
&

"

&

public BinaryTree<T>.Node left, right;


454%

* 3%*364/+*
Contains

Node

&

BinaryTree

2$
"

!
" "
"

)0 (
"

2
'
!

.
!

!)
"-

Contains

&

!)

"!

Node +

!) /

public class BinaryTree<T> where T : IComparable<T>


{
// Aqu se declarara la clase anidada Node
protected Node root;
public void Add(T value)
{
Node parent = null, current = root;
while (current != null && current.value.CompareTo(value) != 0)
{
parent = current;
current = value.CompareTo(current.value) < 0 ?
current.left : current.right;
}
if (current == null)
{
current = new Node(value);
if (parent == null)
root = current;
else if (value.CompareTo(parent.value) < 0)
parent.left = current;
else
parent.right = current;
}
}
public void Add(params T[] values)
{
foreach (T value in values)
Add(value);
}
public bool Contains(T value)
{
return root != null && root.Contains(value) != null;
}
}

"

"!
)

&
bles

Add$

&$
&$

(
%+

. -

nullable types/

"

" !3
"
!"

" $
(

# # #
" +0

&

tipos anula-

) %

T:

&

") .

$
" .

"

"
,

=S?
=SU

$
"

"

"
) "

" 5
"

"

"
&
6$ 8

&

"

"

") )

)+ $ K !
"
(
. 2"
"
& $
2" (
# "
2

"
"
"

"

+ "

$
"

8
)

"
#
"

# +(
- "
2"
"
) ) "
)+ + "

*
"

F
"

& .

. $
. " +
(
&$
%"

"
F
(

)
" "

x$

"
+

"

K !

"

"
(

&
" x y

"

."

(
"
8 2

"

"

private decimal x, y;

."

") - (
"

&.

"
+"

"

" 2
/

# "

private bool nx, ny;

nx

!
!

"

"

"
y$
"

ny

"
"

"
"
(

.
"

+ .
/ K &"

private bool nz;


private decimal z;

// Nos dir si el resultado es nulo o no.


// La suma, si el resultado no es nulo.

if (nx || ny)
nz = true;
else
{
nz = false;
z = x + y;
}

"
$ KC
)

"
"

)
(

&
X

"
(

* !

!
2

&
"+
2 "

&

"

&
.
$
K

=S? "2
) /

) + "
.

.
"
#

&
"

".
) )

private byte clark;


// Superman sin capa y con gafas.
private byte? superman; // Clark Kent con capa y sin gafas.

. &
& )

")

- $
&/

private System.Nullable<byte> superman;

2
+

-T=

&

. -

System.Nullable<T>

public struct Nullable<T> where T : struct


{
private bool hasValue;
internal T value;
}

Nullable

"

"!
$A +

Nullable &
"
Nullable<String>
Nullable

"!

( 3 2

String

'

F
&6(

"

( -Nullable
2" (
" "
Nullable
(
" "
" "
+
")
"

( -

"

") " Byte??$

"
&

"

)
E

"

"

B
B$

&

System.Nullable$

"

Q! / Nullable
!"
!"
"
% &$

.
&
) $

(
.
/D
"
"

"

7 "

# '

"

"

/
$

&

Nullable
Byte?

. (
"

. -

System.String

"

5"&

&.
."

$
(

!"
K

!"

C # +(
$

"

" +"

'
$

"

Nullable

( -

Nullable$

&

"
%

"
2

Nullable

. (
(

) $

"

"

int? i = 1234;
int? j = null;

)
3

)
") -

"

"
&

.
2

"

!
$

!
&

8
")

"

Nullable/
Nullable<int> i = new Nullable<int>(1234);
Nullable<int> j = new Nullable<int>();

"

"

/
int? i = 1234;
int j = i;

" "! !

// Esto no es aceptado por el compilador!

"

&

"

Nullable<T>/
public bool HasValue { get; }
public T Value { get; }

# ')

"

"

TI

int? i = 1234;
int j = i.Value;

%"

"

(
Value

2
8
"

2"

) i
2

$ KC
8

&$

Value

")

HasValue

"

"

/
int? i = 1234;
if (i.HasValue)
{
int j = i.Value;
}

%"
Value

( 3
.
%" $
'

# + .0
"
GetValueOrDefault (

"

) "
"

"

) 4
8
&/

"
2
&

&
&
Nullable

int? i = 1234;
if (i.HasValue)
{
int j = i.GetValueOrDefault();
}

"

"

GetValueOrDefault

&

" + "

public T GetValueOrDefault()
{
return this.value;
}

GetValueOrDefault

"! "
"

"

HasValue +

)
"

/
) %
$
.

" &
2"

)
2"

"

)
. $
&.

,
.

- "
2"
%"
)
2"
)+

$
8

GetValueOrDefault (

"

" &/

public T GetValueOrDefault(T valor_por_omisin);

&

2"

& .

"

int? i = 1234;
int j = i.GetValueOrDefault(-1);

&/ "
"
i
(
8
. " -1$
") . 8
" %
GetValueOrDefault/
"
operador de fusin 9coalescence operator@
.
. &
/
0 "

j +

.
"

int j = i ?? -1;

$
)

-T;

%"
"

.
.
!

"
$

.
(

) $

( &

"GetValueOrDefault
%
.
(
"
"!"
8. (
0
$
%"
.
)
8
& " %
. $

&

! ) .

)*+,

$ GetValueOrDefault "
!"
%
.
(
2"
!

)
!
.

$
)
"
F

2 (

"
)

"

") # )

"!
) %

B$

")
.

" operadores promovidos$


&
.

"
8

( 2
$ K1
(
8
(
) " +
#
"
"
&
lifted operators (
2"
" " (
8
&
$

"

( %
!)
(
"!
F /

int? ni = 1000;
int? nn = null;
ni = ni + 1;
Console.WriteLine(i);
ni = ni * nn;
Console.WriteLine(i);

"

%"

)
) ni$

"

&

ni$
Nullable<T>$

"

&

%"
2
$

WriteLine

"

&

ToString
%
ToString )

"
'
"

$ "
. 1001
+
.

" "

"
"

ToString

"-

.
)

"
.

"

2$
-

&/

ni = ni * null;

2
2

$
"

. " +
F 4
.$ KF -

(
&

"

(
! "

ni

"
2

"

"!

8
) 2"

&

"

$
(
(
2

"!
F

"!
.

8
."

8
.

"

& .

int? ni = 1000;
int? nn = null;
if (ni > nn)
Console.WriteLine("Mayor");
else if (ni < nn)
Console.WriteLine("Menor");
else if (ni == nn)
Console.WriteLine("Igual");
else
Console.WriteLine("Este mundo loco, loco, loco...");

#
"

"

! " (

TS

El Conocimiento Secreto
1
"-

(
. "

& .$
(

% (

"

."

"

)
"! 8
2

(
.

)
(

.)

"
$

10
F

& (

"

$
.

%(

& "
# )2 (
(

"
"

iteradores

. %$

&

"

. % "!
&
!
"
3
. %

)
&

8 /( ")

( -"
"
&
!
. %(
"
))

"
# "
( "!

%
!

2 $
8
+

,
.

. "

& "

"

. %/

&

'

)
( 3

&

" $
"

$
&
$K

.
'

) .
(

3
$

&"

"

&
. "
%"
Boolean$

(
" + 8) $
' )
) ) "

8.
B

. %
2)
( # # #

2
$

8
. % )
+ 8.
(
8
& (

( (

"

(
2
&

%
))
/

.
&

(
"

(
"

"

"

$
&

&" preparar
&

"
&

' contenedores
!)

"
"
"!(

"
"

"

"

"
& +
)

"

$
%

"
"
"
.

&.
"!
&$

&
&
2

"

. "!

(
)

)
.

)
&

(
)
&.
'

"
.
"

"

5
" +

)
Boolean

"
.

%" "
64
+
(

"!

'IDisposable
!%

"
&

foreach (Tipo variable in expresin)


instruccin

2
"
)

" "
( /

)
8
8
")

)
(

"
&

"

"
4 K( -"!
' IEnumerable
7 "

"

"
(
+

F
") 9K

$A+

"

IEnumerable

"

"! "

'IEnumerable

"

System.Collections$
" "
System.Array +-

&

IEnumerable

&$
)

0)
)

9 "
8
.

&

@+. '
" "

"

@$

IEnumerable/

&

public interface IEnumerable


{
IEnumerator GetEnumerator();
}

IEnumerable &

' IEnumerator

"-

System.Collections/

") -

public interface IEnumerator


{
bool MoveNext();
object Current { get; }
void Reset();
}

."

(
&

8
"

&
"

&
.

"
"

IEnumerable$

"
/

IEnumerator enumerador = expresin.GetEnumerator();


while (enumerador.MoveNext())
{
Tipo variable = (Tipo)enumerador.Current;
instruccin;
}

"
& "
K

( )

"

"
"!
& "

&

"!

IEnumerable

"

IDisposable$

# +(
#

'
"
(

IEnumerator$
(
%
GetEnumerator

! "
&

)
/

"!/

+
+

-.

TT
--

8
.!

3
&
(
" "
&
IEnumerator (
) ."

" "

)
"

'

"

-.

'

A+
+

"

8 2 $
=$> "
"
!
)

"
"!

IEnumerator

" .
"
& :$:$ K

2"
0)

")

Current

/
.

'

&
)

&

GetEnumerator$
IEnumerator$
" " T

"

0)

$
%(

tipos genricos

"-

&

0)

&

GetEnumerator
GetEnumerator$

(
/

public bool MoveNext();


public X Current { get; }

IEnumerator 5

86

Current (

!
(

"

"

& +
)

Current

"

&

"
$

"
"

"

(
"
2
"

&

"

(
(

&
%

"! (
#

.
"

"
O
)

5
6
%
" "!
)
)
"'
(
#

"
+
) $
"!/ # +
& .
(
'
)

"

"

si non vero ben trovato$

2
.

"
) (

&
"

""
.

"
) (
'$

& 6$
&

.2

/
&

IEnumerable IEnumerator

"

"

) %

$
.

8
. "

5) (
& &
)
$1

. .

mtodos iteradores$

& =$>
# )

%
"-

8 #

"

"

Q +

BinaryTree = class[X]
public
iterator Nodes: X;
end;

JJ +
)

"2(

+ "# $C

" 6 # +(
"

2
/

public IEnumerable<X> Nodes() { }

Nodes

"K &"

"

) (

&

) (

&

%"

)
"

"(

8 " /

public class Iteradores


{
public static IEnumerable<int> Digitos()
{

-. TV

yield
yield
yield
yield

return
return
return
return

yield
yield
yield
yield

0;
3;
6;
8;

return
return
return
return

1; yield return 2;
4; yield return 5;
7;
9;

}
}

Digitos

") (
"
/

Digitos

!
+

&

(
$

"

foreach (int i in Iteradores.Digitos())


Console.WriteLine(i);

& . "

" 2
"

2
.

"

> V

2 $
"

& &

"
/

foreach ()
{
yield return x;
}

"
"

(
#

(
) $

)
(

&
.

" &

"
)
$

)
+-

&

2 "
"
.
2
%.
"!

"
&$ A )

"

2
)

$
&
2

"

corrutina$

++
)

!
(

) "

&"

"
exactamente

"

"

'

& .

"

'

"
.

&

yield return x;

"
"

"

"

"
.

"
7 "

%"
0"

"!
Q)

"
& "
$

&
)
"

"

.
&
( "!
"

"
(
)! $

&

+
$

'
$
(

") - # +(

"

)
)

'

public static IEnumerable<int> Fibonacci()


{
yield return 0;
int i = 0, j = 1;
while (true)
{
yield return j;
int temp = i;
i = j;

.V>

"-

_estado = i
_current = x;
return true;
i:

"
.
.

+
(
"
' "
/

MoveNext

"
2
$

$
!

'

j += temp;
}
}

"

%
)

0"

.0 " "

E
2
$

%"

.
)

"

(
.

"
&

foreach (int i in Iteradores.Fibonacci())


if (i > 1000)
break;
else
Console.WriteLine(i);
454%

* 3%*364/+*
IEnumerable
P

D
'

Fibonacci 9
D
9%$)"

KF " "
!)
# $

" "
& (
'(
"

BinaryTree

"
"-

&
!)

+
)

7+ "
"
.
!)
"

$
"

"

&

public IEnumerable<T> Nodes()


{
Node current = root;
Stack<Node> stack = new Stack<Node>();
while (true)
if (current != null)
{
stack.Push(current);
current = current.left;
}
else if (stack.Count > 0)
{
current = stack.Pop();
yield return current.value;
current = current.right;
}
else
yield break;
}

#+

"
8 $
Stack (

'"
#

"
"$

"

/
"
$

"
$

$
"

8
"

( &

8 2

"

&"

public IEnumerable<T> NodosRecursivos()


{
if (left != null)
foreach (T valor in left.NodosRecursivos())
yield return valor;
yield return this.value;

V:

if (right != null)
foreach (T valor in right.NodosRecursivos())
yield return valor;
}

K7

) "

'(

'
") )
!) "

"

&
" "
$

"
"+

"
8 $
$

" +!

!
+# ) 2 (
" "
&
. "
&
(

2 8
%

"

. "

$
. % (
"

"

%
"
""- 6

9 . " + 2@
!)
)
)
"
!"
" 5
.
"
"
/

"
(
)

"0

'
$

"- $
. (

6$

"

public class Pila<T>


{
private T[] elementos;
private int cantidad;
}

2"
"

(
.

"

"

"-

public void Recorrer(Action<T> accion)


{
for (int i = cantidad; i > 0;)
accion(elementos[--i]);
}

Action

. -

'

Recorrer

!"

System/

// Delegado predefinido en System


public delegate void Action<T>(T obj);

" iteradores cerrados$


.
5 )
6/
" ) "
BinaryTree$
"
)
/

""
&"

(
. "
8)
"!

"

"

"
.

.
"

(
$

!"
$

"!
.

Action

&

2"

2(

"

- /

public delegate void Action1<T>(T obj, ref bool abortar);

"

2"
2"
"

# ) # # ( Action1
&. $
2
"
"
5 .6
"
' abortar
$
"

"
& "! "
" . (
"
(
"! /
"

$
"
+

.V=

+(
. "

'
&/
&$

2"

!"
) .
!"

2(

!"

$
"
(

"
" '
"
'

(
" '

2"

$
"
!

2
$

"

"
$

'

"
"

E
#

( +
!) )

"

)
.

"

"

&"

4D
"

&
" '

. " 2

"-

public class BinaryTree<T> where T : IComparable<T>


{
public void ForEach(Action<T> action)
{
if (root != null) root.ForEach(action);
}
}

"
"

"

"
&

"

.2

ForEach

"

2
'

"-

Node/
public class BinaryTree<T> where T : IComparable<T>
{
protected class Node
{
public void ForEach(Action<T> action)
{
if (left != null) left.ForEach(action);
action(value);
if (right != null) right.ForEach(action);
}
}
}

KA
"-

( -! #
)

"
+(

' 2 ForEach
$ .

&"
.

"

& 6/
2/

"

private void ImprimirNumero(int i)


{
Console.WriteLine(i);
}

2"
"

Console.WriteLine

"

"

ForEach # 2"

"

"

"

(
$

"

(
%

BinaryTree<int> tree = new BinaryTree<int>();


tree.Add(0, 9, 1, 8, 7, 2, 3, 6, 4, 5);
tree.ForEach(ImprimirNumero);

( 2+
"(

"

) " /

"
$

)
& " $

ForEach (

"

ImprimirNumero$ K &

"

"-

"

.
."

'

!
& .

$
)

.
/

&

"

" -

) "-

BinaryTree<int> tree = new BinaryTree<int>();


tree.Add(0, 9, 1, 8, 7, 2, 3, 6, 4, 5);
tree.ForEach(delegate(int value) { Console.WriteLine(value); });

'
")

"
#2

&
5 & " 6$
"

"
,

""
"-

.$
!"

"(

& "

VI

. $
! %
" " .
& " $

.
2 "
!
"

(
+ "!

"

!"

"-

"
.

)
"$

ForEach +

"

""%"
"

$
"

& (

( -#

"
'

"

."
)
"/

& .$
"

")
&

& "

'

BinaryTree<int> tree = new BinaryTree<int>();


tree.Add(0, 9, 1, 8, 7, 2, 3, 6, 4, 5);
int total = 0;
tree.ForEach(delegate(int value) { total += value; });
Console.WriteLine(total);

'

""
" +

$
"
"

& "

)
8

"

"-

-(
#

")

"-

& " $

"
-"
!"
$

'$

"
" # "!/

int count = 0;
tree.ForEach(delegate { count++; });

"
(

(
-

)*+,

" "
2
2(

!"
"-

)
& "

% $
)
)

)
"

(
9

""
+

)
"+ "
expresiones lambda (
'
B$
")
"
!
& I
. %
. " &
#
2
8
( & " $
. -

".

& "

.
"
8
&
+
. %$

&

")
3
"
)
"-

System.Array (

F
! "
-

)
(

. %
!
3

%"

!
B

. -

"

/
public static T[] FindAll<T>(T[] vector, Predicate<T> condicion);

FindAll

)
.

"

& +
&$

"
&

"

public delegate bool Predicate<T>(T obj);

/
(

"&.

"

.
0"

"
"

Predicate

)
&

int[] result = Array.FindAll<int>(


new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
delegate(int x) { return x % 2 != 0; });
foreach (int i in result)
Console.WriteLine(i);

.V;

+ )
%"
/

'

" + # "

"-

FindAll +

&

&

")

"

& "
"
$

"
%"

FindAll

"

8."

"

) "! "

"

& " $R
/

"

int[] result = Array.FindAll(


new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, x => x % 2 != 0);

"
"

.
"2
$

"

&" #
&

&

") $
(
#

$
)
%" /

"
"!

"

&

(
)%

"
"

"

+
4

delegate(int x) { return x % 2 != 0; }
(int x) => { return x % 2 != 0; }
(int x) => x % 2 != 0
(x) => x % 2 != 0
x => x % 2 != 0

"

&
& =$>$
"
&$A "
")
&
2
")
B

8
)

.
"+( -

")
& "
&
" )
"

(
'(
" $

.
" +

"

"
$
) .
"
$
"

) (
)
8

&
!"
!"

"!

"
)

/
"

&

"

"

"

!
2
")

.
+
=>

.
+

. # "
& " $

"$
&
") #
&

"
) %

&
"

B I$>
" "
!
/
"
8
& ") 4 "
(
)
$
(
"
". - FindAll
"
!"
FindAll
%"
# "
)
8 2 "
!"
B =$>$ D
" -) E

"
!"
" "

"
0 "

& "
"
%
!"

+
) (
(
) (
.
8
&$
(
8
+
"
&
$

FindAll

"

"&

&

!"

8
"
x/

& +
+ "

&

"
(

") $

x => x % 2 != 0

"

& (

)
"
/
"

FindAll

&

.
!"

"

"

x +

FindAll
"
% (
"
.
)
B I$>

0"

( $

"

"
!"
.

&
"

. %

"
&

new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }

$
$C # "
"
&
/

// Antes
// Ahora

(
.

VS

K !
K !
8

8
$ " .

&
8

")
)

"
8)

"

.
.

&
/

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


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

"

"-

"

public void AHandler(object sender, EventArgs e)


{
}

'

"

"+

) " /

MyHandler1 eh1 = AHandler;


MyHandler2 eh2 = AHandler;

") .

"

( %

"

eh1 = eh2;

(
$C

& 8 2

"

'(

(
8

"

&

/
!

AHandler

(
&

"

+ )

%"

% &
(

.
!

&

"
2
"0 Delegate
" !
%+

"
"

. $

AHandler.BeginInvoke(null, null, null, null);

& 2

((MyHandler1)AHandler).BeginInvoke(null, null, null, null);

(
"

$*
"

"

AHandler

&

) $

(
.

8
"

")

)
"

" )
8
(
) "

!
.
. -

(
.

&

.
.
$

"
"

) $

+(
$

System/

public delegate TResult Func<TResult>();


public delegate TResult Func<T1, TResult>(T1 arg1);
public delegate TResult Func<T1, T2, TResult>(T1 arg1, T2 arg2);

4+ 2

"
&

#
")

!"

# "

Func<int, bool> esPar = x => x % 2 == 0;

%"
0"

&

&.

Func

"! (
)

.V?

)
"-

$K

" &

8&
"

)
"

"
(

.
(
. "
"

'

) $K 2
) .
"
" 5
' 6
&
" &
& .
8
8

.
. )
"
% &
" +) %
$

.
&

!)

8
(

'

&

&
4 +
(

")
"

'
) $ KC
"
'
.

/
. -

System.Linq.Expressions/
public class Expression<TDelegado> { }

2
)
"

. %
" Expression$
$A ( 2

.0
"

.
.

%"

Expression<Func<int, bool>> esPar = x => x % 2 == 0;


Func<int, bool> fnPar = esPar.Compile();
if (fnPar(2) && !fnPar(3))
Console.WriteLine("El cielo NO se va a caer.");

"

& . (

&

"

"

ParameterExpression px =
Expression.Parameter(typeof(int), "x");
Expression body = Expression.Equal(
Expression.Modulo(px, Expression.Constant(2, typeof(int))),
Expression.Constant(0, typeof(int)));
Expression<Func<int, bool>> esPar =
Expression.Lambda<Func<int, bool>>(body, px);

"

"
! "
'

)
!)
. /

+
8
%

!)
&

8
.

&

") $

!)

) "

"

"-

Compile (

Func<int, bool> fnPar = esPar.Compile();

)
8

(
&$

!"

VU

11
W

# "

!
(
"

"

. %
. "
. " & &. $
" ) )
. %

"
2" " $
)
"
$
. ") - " %)

.
(
) $ KA
% (
" '
"
.
(
3
4

" "
. %
%

8&
(
# #
)

"
(
+
8
"
(

. "

&

&(

"! )
$C
5
.
"! "

+
"
#+
. "

( #+ " '
&/ (
"! .
+ "!

" $
" .
O $
"!/
. "
- &"
( O
" "

. %
"! 8
" %
%"

O
"0
"
"
. %
"
%
.
&
)
"
. "
(

"
" &
. % "!
)%
#
) $
.
+"
T> $ "
9 " 2 #+
# " + "
V> JJ " '&
(
"
& +
(
"
" &
/
&
2"
$C

.-

.
$
6
. %

"
3

"
)

0
'

"

"

K &"
"
( 2 (
)+

(
$
.&

.0 "
.

1 F

#2
$

%"

"
(

!.
B

" % (
"

. " +

(
"
$
reflexin

.
"
. "
JJ$
(
"-

&
"

+ " . ! (
. %
$
$G
K
( - .
"

&
(

3$
"

" # )
" &(
8
"0
JJ
3
V> @$
" ) Runtime Type Information 91 @
#
"
" &
) $
# "! 1
(
JJ
( #
. %
$
)

8&

"
X/

+
.
/
"
$
(
/#
#
" +
% &
)
$

"
"

."
"
"

2
"
"

3
"
" "

")
$
&

&
#

+
" # "!
" &
"!(
" /"
. 8& $

%0
&:'

" $
& "
.
8&
$
8
(
"! ) %
+
%
"+ 2
0 "
. % $

8&
"

)
" "
&
" & )
( "
.

"

.
") "!
/ Reflection.Emit$
8&

. "
&
)
$
"&
& +
& . %
) $
")

")
&
")

"

atributos$

$
'"

8&

%"
)
" # "
"
5 " 6 + "
System.RuntimeType$ #
)
(
)" "
" ")
#
System.Type$
A+

"

+ 8
&
& .$
"
(
) ,

.
)

"

/
")
) "

"

%
-

)
&

"-

System.Type

'"

&

B$

" .

class Program
{
static void Main(string args[])
{
System.Type t = typeof(Program);
Console.WriteLine(t.FullName);
}
}

FullName

Type

")

")

"

&

$
) !

ConsoleApplication1

Program

%"

"'#

"
) "

+(

"

GetType (

"-

Type

System.Object$ KF -

"

"

"
class Program
{
static void Main(string args[])
{
System.Type t = typeof(Program);
Console.WriteLine(t.FullName);
t = t.GetType();
Console.WriteLine(t.FullName);
}
}

454%

* 3%*364/+*

,
;

"

&

&
.

"!

$
#
$

'(
"
)

System.Type

.
"
)

&
"

'(
/

public Type BaseType { get; }

.. VV

"

"

"

&/

public Type[] GetInterfaces();

0 "
#
" " '

"
$

&

GetInterfaces

"

" 3
.2

"
.
/

static void Main(string[] args)


{
Type t = typeof(int);
while (t != null)
{
Type[] intfs = t.GetInterfaces();
Console.Write(t.FullName);
if (intfs.Length > 0)
{
Console.Write(" implementa");
foreach (Type intf in intfs)
{
Console.Write(" ");
Console.Write(intf.Name);
}
}
Console.WriteLine();
t = t.BaseType;
}
}

. &
&

'

"
/$
0"

&
&

'
'

'#
'. -

")

0"

&

)
"

FullName$

")
"

Name

+
")
"
")
FullName + "
") Name

" + .
$

+1

."

'

"
$

- $
" $
8

+
" " (
(
SqlConnection ( #
.
made in Microsoft
2
+
SqlConnection
'(
"
#+
(
"
"
")
"2$
Cliente.SqlConnection
(
$
")
" '

'&
#

" +

)
" +"
&
(
.

(
""!(

"
(

"

"

"

+"&

" "

)
&

"

$
(
" Assembly +
$

%"

")

Console.WriteLine(typeof(int).Assembly.FullName);

&

:>>

"

"
!

' ") $

System.Data.Sql-

") '

") !
8& ) 2 # )
")
.
System.Reflection$ A +
+
"

Assembly/

"

$
%"
6

SqlConnection 5

$
")

"

'&
"

%0
&:'

5 &

3$'4'4'42
3
3 77 8 89":/; 4<:

display name

"

")

"

2"

.
#

")
/

.
5 &

"2
3

3"'4'4'42

"

'

")
( $
")
"
0)

'

&
3

$
"

"

+%

.0
"
")

mscorlib
!(
'<

!
*

"
")
")&
&$1
" "
4(
0 "

)*+,

")
Program

# )- "

& " !
"
$
$
#
" $

!
(
*

mscorlibA

") -

"

")

"-

Assembly/
public static Assembly GetExecutingAssembly();
public static Assembly GetCallingAssembly();
public static Assembly GetEntryAssembly();

" "" $
.
0 " "'
"
)
.
%
"

(
&$

Assembly

")
")
( % &
$* #
2
.
"
!"

"

""(
#
& "Main (
$

")
&
)

")
") .

.
& 8
)
"")
/

%"
")

" "
")
"

(
")

"
!

%
"
#

#
"
plug-ins$

Load

System.Reflection.Assembly asm = System.Reflection.Assembly.Load(


"System.Data, Version=2.0.0.0, Culture=neutral, " +
"PublicKeyToken=b77a5c561934e089");

% "
")

(
(

"!(
.
!
2
'

" %
"!(
$
(
")
"
$G
(
. % 8

/
.

&
( +

")
)

")
")

&
1

&

+
. %/

:>:

KC
2

")

8
&

F
" " $

"

"
") -

LoadFrom

"

&
# + ") -

"
plug-in
& " +
$

F
!

" "
. plug-ins

&
/

"

")

& 2

Assembly

"

"

")

"-

System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFrom(


@"C:\Windows\Microsoft.net\Framework\v2.0.50727\System.Data.dll");

LoadFrom

(
)

")
. (

8
KF -

"
"

# "
&$

#
")
")

"

"

"

&

"

$
.
"

")
)
")

"

(
Assembly, . "

" asm$
'

(
&

"

foreach (Type t in asm.GetTypes())


if (t.IsPublic)
Console.WriteLine(t.FullName);

"

.
")

'

"

)%
!

"

" 2
"&
"

) "

(
"

&
(

."

IsPublic

"

ofuscar

GetTypes

(
E

(
N

"
")

&
#
& .

)%
.

"
.
%

%
'(

"
+

"

"
"!

"
"

)
&$
(

8&

" ")
# #
0 "
2(
) %

"
2"
(
& 8

) "

plug-ins$

(
+
$

%.

Biblioteca de clases$

"
"
.
:>=

" (
&$
+
+
(
(

2
+ !"

))
' 3
%
%

"
(
$

&
. 3
")
Ventanas/

7
"

M
BackColor

+ 3!
N Q "

"
))
"

8
&
& (
"
+
Aplicacin para Windows
& $ *!(
) &
% &
% ) .
" "
/
"
&
+
+
)

%0
&:'

" "
+

# .

Referencias

!. (

&

) $A+
+
$
) + %
!. +

"
-$

"
"
%

"! "
Load

" " +
.
/#
(
)
"
Agregar referencia
" 0
+
))
/

. "

"
(

"
")

Ventanas

) $

"

&/

private void Form1_Load(object sender, EventArgs e)


{
string filename = Path.Combine(
Application.StartupPath, "ventanas.dll");
if (File.Exists(filename))
{
Assembly asm = Assembly.LoadFrom(filename);
foreach (Type t in asm.GetTypes())
if (t.IsPublic && t.IsSubclassOf(typeof(Form)))
CrearVentana(t);
}
}

"
#

"
Ventanas.dll$

"
#
! Combine
( #+ 8 "
" ) " (
8
+
"-

"-

#
")

'(

)*+,

")

"
Path

)
#

&
8

!
"
+
."

LoadFrom$

!
Form2

#
Ventanas

Form1A
)

'
"

"

0)

")

IsSubclassOf &

"IsAssignableFrom
)% $
0)

+
+ "

Form$

"

"

" "

$
# +(

"-

8
"-

#+

CrearVentana

( # "
'
"
0 "

private void CrearVentana(Type t)


{
Form f = (Form)t.InvokeMember(null,
BindingFlags.CreateInstance | BindingFlags.Instance |
BindingFlags.Public, null, null, new object[0]);
f.Show();
}

:>I

) " (
$7"

"
#

0)

"

!"

)0 (

$ CrearVentana

) %

"-

System.Type/
public object InvokeMember(
string name, BindingFlags invokeAttr, Binder binder,
object target, object[] args);

InvokeMember

"
"

" &$
"
"

.
%

"
/ InvokeMember
"

"
"" $

(
.
" ")

")

"
(

8
.

"-

Instance

"
"" $
"

)
%
"

.
!"
"
+
Public ( 0)
In" "
&$
!"
8
# +(
.
.0 (
!" $
)% (
(
"
"

$ BindingFlags

2
$ CreateInstance

$R
+

& ( # "
$ "
.
$

"

Binder

"
" (
"
")
stance4 )
# +(

"
" ")
%
!

'& (
"

+
"
!"

InvokeMember

"
Esto es un objeto y no una pipa $

(
"

"
'(
"

$
#

"
$

2"
+

"

&
"

+
) "

"

" #
%

"

# )
"
)
"
InvokeMember

"

"-

(
Show$

&
CrearVentana
"CreateInstance

"
"

Assembly/
foreach (Type t in asm.GetTypes())
if (t.IsPublic && t.IsSubclassOf(typeof(Form)))
((Form)asm.CreateInstance(t.FullName)).Show();

%
"-

CreateInstance

"

8) (

)0 (

")

InvokeMember$

'
%"
"

) "
")
2" (
! "

.
(
" 0
(
"
" 0
# +"
"

" +"
+

) " +
& . "

."

"
"

&

' )
&
"!

"

"

"

(
"

!
2

/
(

'"

. $
&$
%"
&
(
! "
"
$ KF - 8
) 2"
"
8 antes
(
$
"

&

// Esto es Delphi:
property Edad: Integer read FEdad write SetEdad default 18;

:>;

'
#/

%0
&:'

(
!
'
# #

)
" &
$
"
.

!
'

# "
"

"

"

'

"

"

&

)
%
"

"

.
"

"

"

9+
#

!
'

$
Edad .

/
#

) (
4

"
$

)
"

&$

. "

%
"

#$A
")

Edad + #

"
& @.

!
$
" "

")
") . /
!
& .
' &
"! "
$
"
)
'

FEdad

"
'

KF " &
" "
.(
! ) %
(
.
"

$ &

"
8

"

" &

& .

.
"!

" +

en tiempo de ejecucin$

&

8 2 "
'

"
&

8
&.
" "
" &

" &
&

" &
&

# ) $
. " &

. %
)$

A %) .
3& B + 2
!
ad hoc
&
" &

&"

"
8
" 3 ( -

. %

$
$ #

&
-

$
"!
B/

'

"

atributos$ 7 "

[DefaultValue(18)]
public int Edad
{
get { }
set { }
}

)
&

"
"

!"
)

& (
% &$
"&
+

&

"

&
")

%"
/

"

)
"& #

[Obsolete("Utilice la clase Cliente")]


public class Persona
{
[DefaultValue(18)]
public int Edad { get { } set { } }
}

Obsolete
Attribute/

ObsoleteAttribute (

"
)

")

:>S

ObsoleteAttribute

0)

Attribute +

(
"

Persona

"

!"

Obsolete-

Persona/

34%/*),
NQ)N9!(!
>
.

A>

!
%!:$.9(+$9.!

;4/ % 3+*%;4 $,/4

15

# +"
" "

Persona & # +

" +
" "!8" $

Persona

# +"
)

Edad +

KF - #
" #
Value
' &
"

8
)

)
#
Obsolete

+
"

Default-

$
" &
"
( %

& .
"
)
"
$
"

WebServiceAttribute (

)
$

&
"
$

"

"

+
Persona$

'
"

"

DefaultValue/

DefaultValueAttribute

"

"

M )

)
"

)
"

+
"

"-

[WebService(
Description="Mi servicio",
Namespace="http://intsight.com/")]
public class MiServicioWeb
{
}

WebService #

'
#
'
.2/ Description +Namespace
WebServiceAttribute
")
)
"
.
"

8
!"

)*+,

!"
"

)
")
!"
$

/
%
)%
!"

"

'
.3
+

B
.
E

,
7
)

"
"
&

"
:>?

%"
")
"
'$

(
"!
8 (

"
(

"
) 2 "

& 8
(

"
"

) "
"
(
"
"

plug-ins$ C

$
(
" 0
"

"
$

) "
"!
8
&

&"
/

%0
&:'

) 2"
8
"
"

") $
)
"
" 0(

7"

"
" "
8
& "
" $

"
)

+
"
+ #

8 $ *
)

"
!

Ventanas/

[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
public class MenuItemAttribute : Attribute
{
private string menuText;
public MenuItemAttribute()
{
this.menuText = String.Empty;
}
public MenuItemAttribute(string menuText)
{
this.menuText = menuText ?? String.Empty;
}
public string MenuText
{
get { return menuText; }
set { menuText = value ?? String.Empty; }
}
}
454%

* 3%*364/+*

E
/ 584 ,
#

" MenuItemAttribute
Attribute "
% +

)
"

"

(
#

System.Attribute$

[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]

MenuItem &

&

0)

/
'

$
(

!
!"
(

9D
"

8 +
' "
+
(

!"

'

0)

E@+(
"!8" $ A +
)
!"
MenuText$
.
(

[MenuItem("Texto para el comando")]


[MenuItem(MenuText = "Texto para el comando")]

"

'"
$

"

- "
&

Ventanas

.
!"

' "
/

"
&

(
%

"

") $
)

"

"

[MenuItem("Primera ventana")]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}

# +(
(
7

"
"

(
(

#
"

%
.

"

:>U

"
"

)
/

Inherited

& . (

" " $
"

)
)

"

" 0

AttributeUsage

' "

)
.

"
#

- $
"
#
"
"

&
$ &
"

* +"
/
. ) Ventanas$
"

)
#

"
"

"

"

"
)

miVentanas

)%

# "
"
" "

"

")
"

MenuStrip

"
". /

"Load
"
8
& + !) "
"
" 0
(

"
"

'$
(

" 0
.

" 0
$
"

2"
$
Form +(

MenuItem/

private void Form1_Load(object sender, EventArgs e)


{
string filename = Path.Combine(
Application.StartupPath, "ventanas.dll");
if (File.Exists(filename))
{
Assembly asm = Assembly.LoadFrom(filename);
foreach (Type t in asm.GetTypes())
if (t.IsPublic && t.IsSubclassOf(typeof(Form)))
CrearMenu(t);
}
}

CrearMenu

8 .
' "

")

(
MenuItem$

. !
)

"
)

" 0

"

&
"

Type/

"-

public object[] GetCustomAttributes(Type attributeType, bool inherit);

&
.
)
.

"-

"

!"
(
(

)
"

)%

'

"

$
$

GetCustomAttributes

"

)
&

"

"

"

$
"

"

"

&

CrearMenu/

private void CrearMenu(Type t)


{
Ventanas.MenuItemAttribute[] attrs =
(Ventanas.MenuItemAttribute[])t.GetCustomAttributes(
typeof(Ventanas.MenuItemAttribute), false);
if (attrs.Length > 0)
{
string menuText = attrs[0].MenuText;
ToolStripItem item = miVentanas.DropDownItems.Add(menuText);
item.Tag = t;

:>
-T

"-

%0
&:'

item.Click += new EventHandler(item_Click);


}
}

"

"+
+ &
- " (

&

"
)
"-

&
(
"
. -

&

&

Object + MenuItemAttribute

" #
"

")

(
.

public static T[] GetAttrs<T>(Type t, bool inherit) where T : Attribute


{
return (T[])t.GetCustomAttributes(typeof(T), inherit);
}

"
+

GetAttrs

&

"

) .

CrearMenu #

$
$
" +
3 -

=$>

'

"

"
+
( # "

)
)
"

)%

"
"

"-

)
"

GetCustomAttributes

.0

Tag

"

"
Click

'"

CrearMenu

" 0
( "

.)

"

Ventanas$

"
"-

" 0
# "

item Click/

private void item_Click(object sender, EventArgs e)


{
ToolStripItem item = sender as ToolStripItem;
if (item != null)
{
Type t = item.Tag as Type;
if (t != null)
CrearVentana(t);
}
}

"&

CrearVentana

( 2

"+

item Click

#
"

% ".

+ "

"

private void CrearVentana(Type t)


{
Form f = (Form)t.InvokeMember(null,
BindingFlags.CreateInstance | BindingFlags.Instance |
BindingFlags.Public, null, null, new object[0]);
f.Show();
}

(
$

" .

(
.0 "

&

)
" (

'

"

"
. "!

"
)

)
"

:>
.V

AppDomain 7
Application
Idle 71
ThreadApplication 71
rboles de expresiones 96
Array 11
assembly Ver ensamblados
Assembly
clase 100
CreateInstance 104
GetTypes 102
Load 101
LoadFrom 102, 103
Type 100
AsyncCallback 55
atributos 104

base 28
BeginInvoke 54
BindingFlags 104
boxing 46

clases
componentes 56
parciales 63
CLR
boxing 46
constructores 28
vectores 11
Combine
Delegate 53
Path 103
constructor 28
esttico 31
operador new 25
struct 42
covarianza 78
CreateInstance 104

DataRow 59
DefaultValue 105
delegados 51, 92
cadenas de 52
expresiones lambda 94
mtodos annimos 92
Delegate
Combine 53
Dispose 69

EndInvoke 54
ensamblados 4
Equals
ValueType 44
EventArgs 61
EventHandler 61
eventos 61
expresiones
rboles de 96
lambda 94

foreach 87
Form
Load 103, 108
Show 104
Func 96

genericidad 72
inferencia de tipos 76, 95
mtodos genricos 76
restricciones 74
tipos anidados 79
GetCallingAssembly 101
GetCustomAttributes 108
GetEntryAssembly 101
GetExecutingAssembly 101
GetHashCode 44
GetTypes
Assembly 102
GetValueOrDefault 84

IAsyncResult 54
IComponent 56
IDisposable 69
Idle 71
IEnumerable 88
IEnumerator 88
indexadores 58
inicializacin
campos 29
clases 28
struct 42
inlining 4
interfaces 35
implementacin explcita 36
implementacin implcita 35
internal 27, 44
InvokeMember 104
IsAssignableFrom 103
IsPublic
Type 102

IsSubclassOf 103
iteracin 87
iteradores 89
iteradores cerrados 92

Load
Assembly 101
Form 103, 108
LoadFrom 102, 103

mtodos 25
annimos 92
de acceso 57, 59
estticos 26, 28, 31
genricos 76
parciales 65
virtuales 30

Nullable 82
GetValueOrDefault 84
HasValue 83
Value 83

ObsoleteAttribute 105
operador
de fusin 84
promovido 85

partial 63, 65
Path
Combine 103
private 27, 44
propiedades 57
automticas 60
indexadores 58
valor por omisin 105
protected 27
public 27, 44

::=

restricciones
desnudas 77

Show 104
static 26
struct 39
constructores 42

ThreadException 71
tipos
anidados 79
anulables 81
de interfaz Ver interfaces
genricos 72
inferencia de 76, 95
ToString 9, 45
Type 99
Assembly 100
GetCustomAttributes 108
InvokeMember 104
IsAssignableFrom 103
IsPublic 102
IsSubclassOf 103

unboxing 47
using
instruccin 69

ValueType 43, 47
Equals 44
visibilidad 27

WaitOne 54

Intuitive C#
Copyright 2004-2007, by Ian Marteens
Prohibida la reproduccin total o parcial de esta obra,
por cualquier medio, sin autorizacin escrita del autor.
Madrid, Espaa, 2007

También podría gustarte