aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT, Building Your First Web Application Project
Advertise Here

Toolbar

Get our toolbar!

Advertize



Posted by Aamir Hasan   on Wednesday, February 2, 2011 Total Views:  

Convert.ToString handles null and not throws ObjectReferenceNullException. ToString does not handles the null value and throws the null exception error message.

Here’s an example

C#

    public String FullName = null;

    protected void Page_Load(object sender, EventArgs e)

    {

 

        try

        {

            Response.Write("<b>.ToString</b><br>");

            Response.Write("FullName :" + FullName.ToString());

        }

        catch (Exception ex)

        {

            Response.Write(ex.Message);

        }

 

        Response.Write("<br><br>");

 

        try

        {

            Response.Write("<b>Convert.ToString</b><br>");

            Response.Write("FullName :" + Convert.ToString(FullName));

        }

        catch (Exception ex)

        {

            Response.Write(ex.Message);

        }

 

    }

 

VB.NET

    Public FullName As [String] = Nothing

    Protected Sub Page_Load(sender As Object, e As EventArgs)

 

        Try

            Response.Write("<b>.ToString</b><br>")

            Response.Write("FullName :" + FullName.ToString())

        Catch ex As Exception

            Response.Write(ex.Message)

        End Try

 

        Response.Write("<br><br>")

 

        Try

            Response.Write("<b>Convert.ToString</b><br>")

            Response.Write("FullName :" + Convert.ToString(FullName))

        Catch ex As Exception

            Response.Write(ex.Message)

        End Try

 

    End Sub


Output

Download

Convert.ToString VS .ToString.rar (747.00 bytes)

See live demo

Protected by Copyscape Online Plagiarism Tool

Comments (1) -

Magnolia Buddemeyer
Magnolia Buddemeyer United States
7/17/2014 11:26:30 PM #

may i knw hw do i knw is the receiver read my message in weechat android ??

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5