This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ConversionBooleanos | |
| { | |
| static void Main() | |
| { | |
| // declaración de variable entera de 32 bits | |
| int x = 123; | |
| // if (x) // Error: "Cannot implicitly convert type 'int' to 'bool'" | |
| { | |
| Console.WriteLine( "El valor de la variable 'x' es distinto de cero."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Persona | |
| { | |
| private string Nombre; | |
| public Persona(string nombre) | |
| { | |
| Nombre = nombre; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PersonaPrueba | |
| { | |
| static void Main() | |
| { | |
| Persona p1 = new Persona("John"); | |
| Persona p2 = new Persona("John"); | |
| Console.WriteLine(p1 == p2); // False | |
| Persona p3 = p1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class IgualdadTiposPrimitivos | |
| { | |
| static void Main() | |
| { | |
| int x = 1; | |
| int y = 2; | |
| int z = 1; | |
| Console.WriteLine(x == y); // False | |
| Console.WriteLine(x == z); // True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class OperadoresComparacion | |
| { | |
| static void Main() | |
| { | |
| int numero1, numero2; | |
| // ingreso de dos números desde la entrada estándar | |
| Console.Write("Ingrese el primer número: "); | |
| numero1 = Convert.ToInt32(Console.ReadLine()); | |
| Console.Write("Ingrese el segundo número: "); | |
| numero2 = Convert.ToInt32(Console.ReadLine()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class OperadoresCondicionalesCortoCircuito | |
| { | |
| public static bool UsarParaguas(bool lluvioso, bool soleado, bool ventoso) | |
| { | |
| return !ventoso && (lluvioso || soleado); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class OperadorCondicional | |
| { | |
| public static int Maximo (int numero1, int numero2) | |
| { | |
| return (numero1 > numero2) ? numero1 : numero2; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LiteralCaracter | |
| { | |
| static void Main() | |
| { | |
| char c = "perls"[4]; | |
| if (c == 's') | |
| { | |
| Console.WriteLine(true); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DeclaracionArreglos | |
| { | |
| static void Main() | |
| { | |
| // Arreglo de una dimensión | |
| int[] numeros = new int[5]; | |
| // Arreglo multidimensional | |
| string[,] nombres = new string[5, 4]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Text; | |
| class PruebaGarbageCollector | |
| { | |
| static void Main() | |
| { | |
| StringBuilder ref1 = new StringBuilder("objeto no. 1"); | |
| Console.WriteLine(ref1); | |
| // En este punto la referencia ref1 de tipo StringBuilder es candidato para el GC |