C#程序使用ToString()方法将各种数据类型转换为字符串

ToString()方法 (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#代码将其他数据类型转换为字符串

// 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


翻译自: https://www.includehelp.com/dot-net/convert-various-data-type-to-string-using-tostring-method.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值