Q:

C# program to convert various data type to string using ToString() method

0

ToString() Method

It is called with a particular type and returns value in string format.

Example:

    Input:
    int a = 10;
    
    Console.WriteLine(a.ToString());

    Output:
    10 //string value 

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C# code to convert other data types to string

// C# program to convert various data type 
// to string using ToString() method
using System;
using System.IO;
using System.Text;

namespace IncludeHelp
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            int a = 10;
            float b = 10.23f;
            double c = 10.23;
            bool d = true;

            Console.WriteLine(a.ToString());
            Console.WriteLine(b.ToString());
            Console.WriteLine(c.ToString());
            Console.WriteLine(d.ToString());

            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}

Output

10
10.23
10.23
True

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now