sábado, 26 de abril de 2008

Dica C#: Entendo os tipos Nullable


using System;
using System.Collections.Generic;
using System.Text;

namespace Estudos_TiposNullable {
/* Autor: Leonardo Melo Santos (leonardomelosantos@gmail.com)
* Data: 26/04/2008
* Descrição: Estudos iniciais sobre "Nullable Types" do .NET 2.0
* Objetivo: Ver tipos primitivos recebendo NULL
*/
class Program {
     static void Main(string[] args) {

         int? i = null; // A interrogação faz parte da sintaxe
         int j = 10;

         Console.WriteLine("i=" + i);
         Console.WriteLine("j=" + j);

         // Vai dar FALSE
         Console.WriteLine("(i == j) " + (i == j));

         // Vai dar FALSE
         Console.WriteLine("(i > j) " + (i > j));

         // Vai dar FALSE
         Console.WriteLine("(i < j) " + (i < j));

         // Usando o "hasValue" para evitar exceções, pois se usarmos
         // "xxx.Value" sem fazer o teste antes, uma exceção é levantada
         if (i.HasValue) {
             Console.WriteLine("'i' não é nulo");
         } else {
             Console.WriteLine("'i' é nulo");
         }

         // Usando o o operador "??"
         int? y;
         y = i ?? 10; //Retorna 10 se "i" for NULL, senão retorna o valor de "i"
         Console.WriteLine("y=" + y.ToString());

         // K será igual a NULL
     int? k = i + j;
         Console.WriteLine("k=i+j");
         Console.WriteLine("k=" + k.ToString());

         // Se "i" for NULL, será retornado o valor default do "int"
         // Senão, retorna o valor atribuído a "i"
         int x = i.GetValueOrDefault();
         Console.WriteLine("x=" + x.ToString());
     }
}
}

Você sabe o que é Lottie no que diz respeito ao mundo das aplicações para Windows?

Lottie-Windows is a library for rendering Adobe AfterEffects animations natively in your applications. This project adds Windows to the Lot...