如何将字符串复制到固定的char数组 [英] how copy string to fixed char array
本文介绍了如何将字符串复制到固定的char数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想复制字符串文件到固定数组。
我该怎么做?
i want copy string file to fixed array.
how can i do that?
namespace Student.Form_s
{
public partial class AddEdite : Form
{
public AddEdite()
{
InitializeComponent();
}
unsafe public struct student
{
public fixed char Name[126];
public fixed char Family[126];
public int ID;
public float mark;
public student* next;
};
public student* start;
private void button1_Click(object sender, EventArgs e)
{
student m = new student();
unsafe{
if(start==null)
{
start = &m;
start->Name[126] = textBox1.Text.ToCharArray();
MessageBox.Show(Convert.ToString(start->Name));
}
}
}
}
}
推荐答案
请参阅我对该问题的评论。我会质疑你是否需要使用修复
;这是第一个要考虑的事情。
但是如果你真的需要,你总是可以逐个字符地复制循环中的字符串。此外,请参阅: http://msdn.microsoft .com / zh-CN / library / system.string.copyto%28v = vs.110%29.aspx [ ^ ]。
-SA
Please see my comment to the question. I would question if you need to usefixed
at all; this is the first thing to think about.
But if you really need to, you can always copy a string in the loop character by character. Besides, please see: http://msdn.microsoft.com/en-us/library/system.string.copyto%28v=vs.110%29.aspx[^].
—SA
这篇关于如何将字符串复制到固定的char数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文