Check for length too when you check for null strings in VB.Net and C# Verificare la presenza di lunghezza troppo quando si verifica per nulla stringhe in VB.Net e C #
Its a good idea to check for null object reference to prevent NullReferenceException when it comes to objects but in case of Strings sometimes you get a string without any value or called as Empty string. La sua è una buona idea per verificare null oggetto di riferimento per prevenire NullReferenceException quando si tratta di oggetti, ma in caso di Archi a volte si ottiene una stringa senza alcun valore o chiamati come stringa vuota. I have faced this a lot of time when I handle exceptions and the error message ( which is a string ) turns out to be empty hence there is no meaning to show that message or store it in database. Ho affrontato questo un sacco di tempo quando ho gestire eccezioni e il messaggio di errore (che è una stringa) risulta essere vuoto quindi non vi è alcun significato per mostrare che il messaggio o lasciarlo nel database. So the good idea is to check for null and for emptiness ( zero length string ) bot at the same time. Quindi la buona idea è quella di verificare la presenza di nulla e di vuoto (stringa di lunghezza zero) bot allo stesso tempo.
‘[ Visual Basic ] '[Visual Basic]
Sub CheckNullString ( ByVal msg as String ) Sub CheckNullString (ByVal msg come String)
if msg is nothing or Else msg.length = 0 Then Exit Sub msg se è nulla o Altre msg.length = 0 Then Exit Sub
‘ Do whatever you want in case both are false. 'Fate quello che volete nel caso in cui entrambi sono falsi.
End Sub End Sub
// C# / / C #
public void checkNullString ( string msg ) public void checkNullString (stringa msg)
{ (
if ( msg == null || msg.Length == 0 ) return; if (msg == null | | msg.Length == 0) return;
// Do whatever you want here in case both are false. / / Fate quello che volete qui nel caso in cui entrambi sono falsi.
} )
This is one good way I was able to find . Questo è un buon modo sono stato in grado di trovare. How do you check your strings ? Come si controlla la tua stringhe? Do share with us in comments . Non condividere con noi nei commenti.
Tags: Tag: comments check verificare commenti , emptiness vuoto , empty string stringa vuota , error message messaggio di errore , null object null oggetto , object reference oggetto di riferimento

Ashish Mohta Ashish Mohta is A tech blogger who writes about solving day to day problems of people who use computer. Una tecnologia è blogger che scrive circa la risoluzione di giorno in giorno i problemi delle persone che usano i computer. He also writes on How to use the applications like Office, PC tips, Online tools,Browsers and more. All posts by Egli scrive anche su come utilizzare le applicazioni di Office come, PC suggerimenti, strumenti on-line, browser e molto altro ancora. Tutti i posti da Ashish Mohta Ashish Mohta | Connect with me @ | Collegare con me @ Twitter Twitter | | Linkedin LinkedIn | | Facebook Facebook | | Stumble Stumble | Need more help? | Serve ulteriore aiuto? Ask your Questions at our Le vostre domande al nostro Support Center Support Center






























Free Email Subscription


Leave your response! Lascia la tua risposta!