Results 1 to 7 of 7

Thread: Difference between String.Convert Vs String.ToString

  1. #1
    Junior Member
    Join Date
    Feb 2007
    Answers
    17

    Difference between String.Convert Vs String.ToString

    Hi

    Please explain the Difference between Convert Vs String.ToString

    Last edited by jbanx; 02-22-2007 at 02:12 AM.

  2. #2
    Contributing Member
    Join Date
    May 2007
    Answers
    60

    Re: Difference between String.Convert Vs String.ToString

    Hi,

    Diffrence between string.convert vs string.tostring is here tostring doesnot handle null values where as covert handle null values.

    Regards,
    hari prasad


  3. #3
    Junior Member
    Join Date
    Feb 2007
    Answers
    17

    Re: Difference between String.Convert Vs String.ToString

    To tell you more Convert internally uses toString. In convert first there is a check for null, if there is null then string.empty is returned, else normal toString method is called


  4. #4
    Contributing Member
    Join Date
    Nov 2007
    Answers
    46

    Re: Difference between String.Convert Vs String.ToString

    String.Convert:
    convert the string from one to another.
    String.toString:
    divide the string into sub string


  5. #5
    Junior Member
    Join Date
    Jan 2008
    Answers
    1

    Re: Difference between String.Convert Vs String.ToString

    String.Convert will not allow null value
    String.ToString will allow null value...


  6. #6
    Junior Member
    Join Date
    Feb 2008
    Answers
    17

    Re: Difference between String.Convert Vs String.ToString

    Quote Originally Posted by jr.suthan View Post
    String.Convert will not allow null value
    String.ToString will allow null value...
    String.Convert:
    convert the string from one to another.
    String.toString:
    divide the string into sub string


  7. #7

    Re: Difference between String.Convert Vs String.ToString

    See the example.

    Line 1 :String str1 = null;
    Line 2: Console.WriteLine("->" + Convert.ToString(str1) + "<-";
    Line 3: Console.WriteLine("->" + str1.ToString() + "<-");

    In the above example,
    Line 2 will display the result("-><-"), because Convert.ToString() handle NULL.
    Line 3 will throw NullReferenceException because .ToString() does not handle NULL.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact