Home » C# » C# programs » C# basic programs

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

C# conversion from other type to string: Here, we are writing a C# program – it will convert various types of values to the string using To.String() method.
Submitted by IncludeHelp, on April 06, 2019

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 

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.