如何将char数组分配给字符串 [英] How to assign a char array to a string

查看:76
本文介绍了如何将char数组分配给字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

问题在上面.
我有一个char数组(可以说长度为1000).
我想将其分配给字符串(不是字符串数组).

我该如何实现?

最好的问候...

Hi everyone.

The question is above.
I have a char array(let''s say with length of 1000).
I want to assign it to a string(not a string array).

How can I achieve it?

My best regards...

推荐答案

您可以使用此 ^ ]的字符串类 [
You can use this constructor[^] of the String Class[^].
string s = new string(myCharArray);




您可以简单地将其传递给字符串构造函数
Hi,

You can simply pass it into the string constructor
char[] arr = new char[] {'a','b','c'};
string s = new string(arr);


尽管这不是确切的赋值,但由于类型安全,这是不可能的.

干杯,鲍里斯


Though it''s not exactly an assignment, which would be impossible because of type safety.

Cheers, Boris


这篇关于如何将char数组分配给字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆