Como transformar string ou int em enumeradores

Voce ja esta familiarizado com o conceito de enumeradores? Nao? E com o conceito type-safe?

Exemplos de type-safe com enumeradores:

string Nome = string.Empty;
System.Drawing.Color.Blue;

Mas como que eu crio enumeradores para comeco de conversa:

public enum Ativo
{
      Nao = 0,
      Sim = 1,
}

Agora vamos ao que interessa:

int Ativow = 1;
Ativo at = (Ativo)Enum.Parse(typeof(Ativo), Ativow.ToString(), true);
switch (at)
{
      case Ativo.Nao:
            return "inativo";
            break;
      case Ativo.Sim:
            return "ativo";
            break;
}

Postado em s 23/11/2007 13:11:25 by Gh0stman

Permalink | Comments (0) | Post RSSRSS comment feed |

Categorias: ASP.NET | C# | Dicas

Tags: , , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

janeiro 6. 2009 05:36