Code Rewind
When its time to find, Hit Rewind
                 
 
 
Remember Me  
Recover Password
 
 Advanced Search
 
 Add to IE Search 
 
 
> Development > Application Development > Languages > .NET => How to create a reusable method to check null or an empty string
 

Available Files:
You must be signed in to download files.
You can Sign Up here if you are not a member.
Author: Administrator
Level: 3
Date Posted: 13-Nov-2008 (08:29)
Last Updated: 13-Nov-2008 (08:29)
Views: 1,246
Favorited: 0
Votes:
  -  1 votes
Your vote:
Click to rate Click to rate Click to rate Click to rate Click to rate
(5 Stars)
Rating: 5.00 out of 5


Summary: We always need some utility methods handy to speed up our development activity. The method in this article shows how to check if a string is null or empty.

Introduction:
How to create a reusable method to check null or an empty string. 

Elaboration:
This Function shows how to pass a String value and check if it is null or empty. This is the most optimized and fastest way to check this. You can also wrap this in a separate utility class.

 

/// <summary>
/// IsNullOrEmpty method will check for if a string is empty or Null
/// </summary>
/// <param name="stringVar"></param>
/// <returns>returns Boolean</returns>///
public static bool IsNullOrEmpty(string stringVar)
{
bool b = false;
if (stringVar == null || stringVar.Length == 0 || stringVar == " ")
{
b =
true;
}
return b;
}

How to use this method?

string UserName = "";

// Check if UserName is empty or null
if (!IsNullOrEmpty(UserName))
{
  //Place your code logic when it is not null or empty
}

Version Tracking:

Version 1.0

 
KeyWords: Generic / None,C# (Generic / None,C# 1.0,C# 2.0,C# 3.0 (Orcas));Generic / None,.NET Framework (.NET 2.0,.NET 2.1,.NET 3.0);Generic / None (Generic / None);
CR Suggested .NET Articles
 
Multi-Threading in .NET by it2max (09-Aug-2007)
 
Most Recent Views
 
What happens to the .NET Code you write? by Guest (08-Sep-2010 02:11)
Handling KeyPress and KeyDown Events for Datagridview by Guest (08-Sep-2010 02:11)
How to insert an array into a Database by Guest (08-Sep-2010 00:23)
Simple ASP.NET Login Using MS Access by Guest (08-Sep-2010 00:17)
How to Access ADO Recordset from ADO.NET by Guest (08-Sep-2010 00:16)
 
 Messages: 0, Topics: 0. Post New Message Please login to post a message...
  View
Items per page
Message since
  TOPIC
AUTHOR
VIEWS
REPLIES
LAST POST
No messages boards...

Post New Message      
General Comment News / Info Question Answer Joke / Game Admin Answer
SEARCH ON FORUM
 
 
   
 
 
TOP USERS
 
No top users
 
 
TOP DISCUSSIONS
 
No popular discussions
 
 
SPONSORED ADS
 
 
 
 



 
Registered Members: 1621
Now Browsing: 6
 
Subscribe to newsletter
 
 

 
IT2Max
RapidConvert
AtHomeTution
TheBusinessXP
 








 
About Us  |  Contact Us   |  Privacy Policy  |  Legal Notice  |  Terms and Conditions  |  Help   |  Browse CR   |  Articles  |  Webcasts  |  Ask an Expert   |  Message Boards   |  Downloads  |  Open Arena   |  FAQ | DaniWeb | GetAHelpdesk | ProgTalk
Copyright © 2007 CodeRewind.com. All rights reserved
designed by IT2Max, INC.
 
Execution Time: 1.92 sec