-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (57 loc) · 1.48 KB
/
Copy pathProgram.cs
File metadata and controls
58 lines (57 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Created by SharpDevelop.
* User: tomm
* Date: 11/12/2017
* Time: 03:16 a.m.
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace ej3
{
delegate void PrecioCambiadoEventHandler(object sender, PrecioCambiadoEventArgs e);
class Program
{
public static void Main(string[] args) {
/* ejercicio 3 */
Articulo a=new Articulo();
a.PrecioCambiado += new PrecioCambiadoEventHandler(precioCambiado);
a.Codigo = 1;
a.Precio = 10;
a.Precio = 12;
a.Precio = 12;
a.Precio = 14;
System.Console.WriteLine("Presione una tecla para continuar");
Console.ReadKey(true);
}
public static void precioCambiado(object sender, PrecioCambiadoEventArgs e){
string texto="Artículo {0} valía {1} y ahora vale {2}";
Console.WriteLine(texto,e.Codigo,e.PrecioAnterior,e.PrecioNuevo);
}
}
class PrecioCambiadoEventArgs
{
public int Codigo{get;set;}
public double PrecioAnterior{get;set;}
public double PrecioNuevo{get;set;}
}
class Articulo
{
public int Codigo{get;set;}
private double precio;
public double Precio{
get{return precio;}
set{
if(!precio.Equals(value)){
precioCambiado(this, new PrecioCambiadoEventArgs(){Codigo=Codigo, PrecioNuevo=value,PrecioAnterior=precio});
precio=value;
}
}
}
private PrecioCambiadoEventHandler precioCambiado;
public event PrecioCambiadoEventHandler PrecioCambiado{
add{precioCambiado+=value;}
remove{precioCambiado-=value;}
}
}
}