Convert.ToString(), .ToString() and (string)
All these are used for converting an object into a string, but they differ the way they handle NULL values.
>> Convert.ToString() returns String.Empty while attempting to convert a NULL object into a string.
>> .ToString() throws an exception in such cases
>> While, (string) cast sets a string variable as "null" value, and do not throw any exception, but if you try to access any property, method it throws an exception.
Wednesday, April 11, 2012
C#.NET - Difference between Convert.ToString(), .ToString(), and (string) cast
Labels:
(string),
C#.NET,
cast,
Convert.ToString,
ToString
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2012
(49)
-
▼
April
(24)
- Get only Date part for SQL Server DateTime value
- Membership in ASP.NET MVC 4 (System.Web.Providers)
- Binding two or more types of objects (models) to s...
- Implement Custom Validation in ASP.NET MVC
- Simple client-side Validations using ASP.NET MVC
- Investigation: Values do not retain in model while...
- Data Binding to RadioButton in a View in MVC
- Investigation: SelectedIndexChanged not firing for...
- Investigation: ExecuteNonQuery() always returns -1
- Development and Deployment - Troubleshooting, Inve...
- Print Page Content to printer (or virtual print ou...
- Show long text in Tooltip
- Auto login into Team system with your authorized c...
- Visual Studio .NET - Some handy shortcuts
- Write custom events for User Controls in ASP.NET
- SQL Query to return each date of month in each dif...
- How to debug ASP.NET Windows Service
- FIX: Add a 32-bit SQL Server 2000 as a Linked serv...
- Difference between integer Cast and Convert in C#
- Optimizing SQL Code by replacing IF..ELSE with CAS...
- Check Authentication Mode in ASP.NET
- How to validate a page using Java script
- SQL Query - To search for a column (by column name...
- C#.NET - Difference between Convert.ToString(), .T...
-
▼
April
(24)
No comments:
Post a Comment
Thanks for visiting my blog.
However, if this helped you in any way, please take a moment to write a comment.
Thanks
Nirman