Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demostración de varios operadores con tipos nullable.
using System;
namespace Articulos.Cap04.TiposNullables
{
public sealed class LiftingOperadores
{
public static void Main()
{
// Declaración de variables nullable:
int? x = 13;
int? y = null;
// Ejemplos con operadores de igualdad:
Console.WriteLine ("\n--- Ejemplos de Operadores de Igualdad ---\n");
Console.WriteLine ("\tx == y -> {0:3}", (x == y)); // False
Console.WriteLine ("\tx == null -> {0}", (x == null)); // False
Console.WriteLine ("\tx == 13 -> {0}", (x == 13)); // True
Console.WriteLine ("\ty == null -> {0}", (y == null)); // True
Console.WriteLine ("\ty == 13 -> {0}", (y == 13)); // False
Console.WriteLine ("\ty != 13 -> {0}", (y != 13)); // True
Console.WriteLine ("\n--- Ejemplos de Operadores Relacionales ---\n");
Console.WriteLine ("\tx < 17 -> {0}", (x < 17)); // True
Console.WriteLine ("\ty < 17 -> {0}", (y < 17)); // False
Console.WriteLine ("\ty > 17 -> {0}", (y > 17)); // False
Console.WriteLine ("\n--- Ejemplos de Otros Operadores ---\n");
Console.WriteLine ("\tx + 13 -> {0}", (x + 13)); // 26
Console.WriteLine ("\tx + y -> {0}", (x + y)); // null (no imprime nada)
Console.WriteLine ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.