Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created September 1, 2014 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/ad8147e36e956e16ffb5 to your computer and use it in GitHub Desktop.
Save Fhernd/ad8147e36e956e16ffb5 to your computer and use it in GitHub Desktop.
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