2 poo u1 5 operaciones
TRANSCRIPT
![Page 1: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/1.jpg)
M.C Ivan Rivalcoba
PROGRAMACIÓN ORIENTADA A
OBJETOSC# & .NET
1. FUNDAMENTOS POO (OOP)OPERACIONES
![Page 2: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/2.jpg)
C# cuenta con operaciones básicas que nos permitirán trabajar con los valores de las variables que hemos creado.
OPERACIONES
![Page 3: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/3.jpg)
Continuando con la práctica, para realizar las operaciones se procede como sigue:
Esta expresión se lee de izquierda a derecha, y el igual es un operador de asignación no de igualación.
OPERACIONES
![Page 4: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/4.jpg)
Por último se imprime el resultado, para ello utilizamos WriteLine.
OPERACIONES
![Page 5: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/5.jpg)
Ejecutamos el programa y observamos el siguiente resultado:
¿Qué ha ocurrido?, ¿Qué es esa sintaxis en el WriteLine?
OPERACIONES
![Page 6: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/6.jpg)
WriteLine permite un código especial dentro del string, mismo que le permite armar una cadena de salida con valores obtenidos de las variables.
En este caso los caracteres {0}, {1}, {2}, sirven como espacios apartados donde se colocaran valores en función del valor de una variable, los números indican la posición después de la primera coma una vez que la cadena ha terminado:
OPERACIONES
0 1 2
![Page 7: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/7.jpg)
Ahora crearemos una nueva practica en donde veremos algunas formas de usar el WriteLine.
Dicha práctica será llamada pk3_datausage.El código se lista a continuación:
OPERACIONES
![Page 8: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/8.jpg)
OPERACIONES
Continuación.
![Page 9: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/9.jpg)
OPERACIONES
Al compilar y ejecutar vemos el siguiente resultado.
![Page 10: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/10.jpg)
OPERACIONES
En este ejercicio hemos introducido nuevos conceptos muy interesantes revisemos.
Using nos permite indicarle al compilador que estaremos haciendo uso del espacio de nombres System, esto nos permite omitir el espacio de nombres en cada invocación de Console.WriteLine.
![Page 11: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/11.jpg)
OPERACIONES
Operación de concatenación: Cuando el operador de suma se usa sobre dos strings, el resultado es un nuevo string con la unión de los dos strings, a esta operación se le llama concatenación.
![Page 12: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/12.jpg)
OPERACIONES
La concatenación, se puede usar para armar un sofisticado string de salida para WriteLline.
![Page 13: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/13.jpg)
OPERACIONES
Es posible pasarle como parámetro a WriteLine una operación, el compilador resuelve primero la operación, posteriormente realza una conversión interna del resultado numérico en un string y al final ese es el string que le es pasado al método WriteLine.
![Page 14: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/14.jpg)
OPERACIONES
De forma gráfica pasa esto.Precio1 + precio 2
12.0 + 23.0
35.0
“35”
Console.WriteLine(“35”);
![Page 15: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/15.jpg)
OPERACIONES
Usando la notación de llaves, los valores entre las comas también aceptan operaciones.
![Page 16: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/16.jpg)
OPERACIONES
Haciéndolo correctamente uno puede dividir una sentencia en varias líneas.
Estas dos sentencias son equivalentes:
![Page 17: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/17.jpg)
ERRORES COMUNES
Usar la variable sin inicializarla:
![Page 18: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/18.jpg)
ERRORES COMUNES
Usar una variable no declarada:
![Page 19: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/19.jpg)
ERRORES COMUNES
No tener cuidado con los tipos de datos:
![Page 20: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/20.jpg)
ERRORES COMUNES
Asignar un tipo de dato de grado mayor a uno de grado menor:
![Page 21: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/21.jpg)
ERRORES COMUNES
Sin embargo Asignar un tipo de dato de grado menor a uno de grado mayor es perfectamente aceptable:
![Page 22: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/22.jpg)
ERRORES COMUNES
Tener cuidado con el uso de las literales.
![Page 23: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/23.jpg)
ERRORES COMUNES
No agregar el atributo static a atributos que pertenecen a clases estáticas.
![Page 24: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/24.jpg)
PRIORIDAD DE OPERACIONES
¿Cuanto daría esta operación en C#?
![Page 25: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/25.jpg)
PRIORIDAD DE OPERACIONES
Reglas de prioridad.
![Page 26: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/26.jpg)
PRIORIDAD DE OPERACIONES
Ejercicio.¿Cuanto daría esta operación en C#?
![Page 27: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/27.jpg)
PRIORIDAD DE OPERACIONES
Respuesta
![Page 28: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/28.jpg)
¿Para que nos sirve el keyword "using"?
¿Que imprimirá la siguiente sentencia?
Q & A
![Page 29: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/29.jpg)
¿La siguiente sentencia es correcta?
Q & A
![Page 30: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/30.jpg)
¿La siguiente sentencia es correcta?
Q & A
![Page 31: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/31.jpg)
¿Hay algo malo en el siguiente código? ¿Qué es?
Q & A
![Page 32: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/32.jpg)
¿Hay algo malo en el siguiente código? ¿Qué es?
Q & A
![Page 33: 2 poo u1 5 operaciones](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55d2abbcbb61ebe65e8b45a0/html5/thumbnails/33.jpg)
¿Cuánto dará “e” en el siguiente programa?
Q & A