Renato Haddad

MVP, Developer .NET and MS-Office, MCPD, MCTS

Convertendo e Validando dados Text para int no C#

Em certos casos de uma interface de usuário onde é preciso verificar se o campo é numérico ou não, use o TryParse. veja o código a seguir onde a variável qtde (do tipo int) está referenciada no out do TryParse. ele retorna true/false e se converter, beleza; caso contrário vc trata.

int qtde; 
if (int.TryParse(txtQtde.Text.Trim(), out qtde) == false)
{
     MessageBox.Show("mensagem")
     return;

}

O VB.NET também aceita isto, mas o VB.NET tem o IF (IsNumeric(txtQtde.Text)... Bendito VB.NET :)

Posted: Aug 11 2009, 11:35 PM by renatohaddad | with 8 comment(s)
Filed under:

Comments

Convertendo e Validando dados Text para int no C# | ASP Scribe said:

Pingback from  Convertendo e Validando dados Text para int no C# | ASP Scribe

# August 11, 2009 10:37 PM

iaece said:

Que, internamente, recorre ao mesmo TryParse. ;)

# August 12, 2009 7:03 AM

Indian Curry Recipes said:

"I was wondering if you will be interested in becoming a visitor poster on my blog? and in trade you might set a hyperlink the submit? Please let me know  whenever you get a chance and I will send you my get in touch with particulars - thanks.  Anyway, in my language, you can find not a lot great source such as this."

--------------------------------------------

my website is  

http://shirtsshirt.net

Also welcome you!

# December 3, 2010 4:27 AM

rare tech decks said:

"Whats up, I am thrilled to skim all of of this web site and am extremely elated and thrilled to guess that the proprietor is performing a incredibly wonderful position here to put all the  content material and facts in 1 place, i should recommend this facts which has a suggestion on my site."

--------------------------------------------

my website is <a href="zeroskateboards.org/.../newsoul-skateboards-albert-nyberg-and-jean-marc-soulet-jutan.html">albert nyberg</a> .Also welcome you!

# December 3, 2010 12:10 PM

ipad app folders said:

When all else is lost the future still remains.

-----------------------------------

# December 18, 2010 11:20 AM

ipad accessories said:

-----------------------------------------------------------

"I am speechless. This is often a exceptional weblog and very participating very. Fantastic operate! That is not really very much approaching from an amateur publisher like me, but it is all I  could say after diving into your posts. Excellent grammar and vocabulary. As opposed to other blogs. You seriously know what you are speaking about very. A lot that you just  produced me desire to discover more. Your blog has develop into a stepping stone for me, my fellow blogger. Many thanks for that detailed journey. I really loved the 8 posts  that I have study thus far. "

# January 8, 2011 5:00 AM

voip reviews said:

A mutual friend stated I must come take a look at your site. Glad I clicked around the website link! I like how you really focus and get to your bottom line but can you operate by way of that last portion again? Just just a little?

--------------------------------------------------------------------    

Biology, Organismic and Evolutionary

# March 12, 2011 9:18 PM

how to build iphone apps said:

"Have you ever considered including far more movies in your blog site posts to hold the readers far more entertained? I imply I just study via the whole article of yours  and it was fairly very good but considering that I am additional of a visual learner,I observed that to be far more helpful. Just my my thought, Beneficial luck   "

--------------------------------------------------------------------        

Earth and Planetary Sciences

# April 27, 2011 9:55 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)