Il Modo Corretto Di Parsare Gli Enum In Asp.NET C#

Posted by: ollie10 6/22/2009 5:02 PM

Per comparare gli enum con le string il metodo corretto è usare Enum.Parse rispetto a comparare le stringhe.

In questo esempio supponiamo di avere una stringa messageId ed un enumerator MessageType:

MessageType messageType = (MessageType)System.Enum.Parse(typeof(MessageType),messageId,true);

L'ultimo argomento dy System.Enum.Parse specifica se il confronto deve essere case sensitive o meno.

Tags: , , ,
Categories: Asp.NET - C#
Permalink | Comments (0)
RSS comment feed

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading