c#中将整数转化为字符串_在C#中将字符转换为字符串

c#中将整数转化为字符串

Given a character and we have to convert it into a string in C#.

给定一个字符,我们必须在C#中将其转换为字符串。

将char转换为字符串 (Converting char to string)

To convert a character to the string, we use ToString() method, we call method with the character and it returns string converting Unicode character to the string.

要将字符转换为字符串 ,我们使用ToString()方法,使用该字符调用method,它返回将Unicode字符转换为字符串的字符串。

Example:

例:

    Input:
    char chr = 'X';
    
    Function call:
    string str = chr.ToString();

    Output:
    str: "X"

C#示例将字符转换为字符串 (C# Example to convert a character to the string )

In this example, we have a character and converting it into the string, and also we have a string and convert all characters to the string in the strings and printing the types and values.

在此示例中,我们有一个字符并将其转换为字符串,也有一个字符串并将所有字符转换为字符串中的字符串并打印类型和值。

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //character variable
            char chr = 'X';

            //converting char to string
            string str = chr.ToString();

            //printing types and values
            Console.WriteLine("Type of chr: " + chr.GetType());
            Console.WriteLine("Type of str: " + str.GetType());

            Console.WriteLine("chr: " + chr);
            Console.WriteLine("str: " + str);
            
            //converting each characters of string into string[]
            string str1 = "Hello world!";
            string temp_str ="";
            foreach (char item in str1)
            {
                Console.WriteLine("value: {0}, Type: {1}", item, item.GetType());
                temp_str = item.ToString();
                //converting and print char as string
                Console.WriteLine("value: {0}, Type: {1}", temp_str, temp_str.GetType());
            }

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

Output

输出量

Type of chr: System.Char
Type of str: System.String
chr: X
str: X
value: H, Type: System.Char
value: H, Type: System.String
value: e, Type: System.Char
value: e, Type: System.String
value: l, Type: System.Char
value: l, Type: System.String
value: l, Type: System.Char
value: l, Type: System.String
value: o, Type: System.Char
value: o, Type: System.String
value:  , Type: System.Char
value:  , Type: System.String
value: w, Type: System.Char
value: w, Type: System.String
value: o, Type: System.Char
value: o, Type: System.String
value: r, Type: System.Char
value: r, Type: System.String
value: l, Type: System.Char
value: l, Type: System.String
value: d, Type: System.Char
value: d, Type: System.String
value: !, Type: System.Char
value: !, Type: System.String



翻译自: https://www.includehelp.com/dot-net/convert-a-character-to-the-string-in-c-sharp.aspx

c#中将整数转化为字符串

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值