str = tempCD.toString() tempCD=['5','4','9','1','3','6','\u0000','\u0000']再ktolin中怎样把该组数组转换成一个是594136的整数
时间: 2024-06-17 20:00:48 浏览: 8
要将数组tempCD转换成整数594136,可以采取以下步骤:
1. 将tempCD中的非空字符转换为字符串并拼接成一个字符串。
2. 将得到的字符串转换为整数类型。
具体实现代码如下:
```
int i = 0;
string str;
while (tempCD[i] != '\u0000') {
str += tempCD[i];
i++;
}
int num = stoi(str);
```
其中,while循环中的条件`tempCD[i] != '\u0000'`表示只要数组中还有非空字符,就将其拼接到字符串str中。最后,使用stoi函数将str转换为整数num。
相关问题
dataInfo = new DeviceManage.设备运行(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Selected == true) { dataInfo.dev_no = sbbh.Text = dataGridView1.Rows[i].Cells[0].Value.ToString(); dataInfo.date = dateTimePicker1.Text = dataGridView1.Rows[i].Cells[1].Value.ToString(); dataInfo.starttime = dateTimePicker2.Text = dataGridView1.Rows[i].Cells[2].Value.ToString(); dataInfo.endtime = dateTimePicker3.Text = dataGridView1.Rows[i].Cells[3].Value.ToString(); dataInfo.endwhy = tjyy.Text = dataGridView1.Rows[i].Cells[4].Value.ToString(); dataInfo.devstatus = yxzt.Text = dataGridView1.Rows[i].Cells[5].Value.ToString(); dataInfo.remark = bz.Text = dataGridView1.Rows[i].Cells[6].Value.ToString(); } 同义改写
以下是对上述代码的同义改写:
```
DeviceManage.设备运行 dataInfo = new DeviceManage.设备运行();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Selected == true)
{
sbbh.Text = dataGridView1.Rows[i].Cells[0].Value.ToString();
dateTimePicker1.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
dateTimePicker2.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
dateTimePicker3.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
tjyy.Text = dataGridView1.Rows[i].Cells[4].Value.ToString();
yxzt.Text = dataGridView1.Rows[i].Cells[5].Value.ToString();
bz.Text = dataGridView1.Rows[i].Cells[6].Value.ToString();
dataInfo.dev_no = sbbh.Text;
dataInfo.date = dateTimePicker1.Text;
dataInfo.starttime = dateTimePicker2.Text;
dataInfo.endtime = dateTimePicker3.Text;
dataInfo.endwhy = tjyy.Text;
dataInfo.devstatus = yxzt.Text;
dataInfo.remark = bz.Text;
}
}
```
这个代码段的作用是将选中的行中的数据填充到表单上,并将该行数据保存在 `dataInfo` 对象中。同义改写后的代码与原代码的功能相同,只是稍微重构了一下。
dataInfo = new 用户基本信息(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Selected == true) { dataInfo.No = yhbh.Text = dataGridView1.Rows[i].Cells[0].Value.ToString(); dataInfo.Name = yhmc.Text = dataGridView1.Rows[i].Cells[1].Value.ToString(); dataInfo.Password = yhmm.Text = dataGridView1.Rows[i].Cells[2].Value.ToString(); dataInfo.Dept = bm.Text = dataGridView1.Rows[i].Cells[3].Value.ToString(); dataInfo.Nation = zw.Text = dataGridView1.Rows[i].Cells[5].Value.ToString(); dataInfo.Job = textBox11.Text = dataGridView1.Rows[i].Cells[4].Value.ToString(); dataInfo.Birthday = dateTimePicker1.Text = dataGridView1.Rows[i].Cells[6].Value.ToString(); dataInfo.Phone = dh.Text = dataGridView1.Rows[i].Cells[7].Value.ToString(); dataInfo.Mail = yx.Text = dataGridView1.Rows[i].Cells[8].Value.ToString(); } }转化成不一样的代码
以下是可能的另一种实现方式:
```
if (dataGridView1.SelectedRows.Count > 0) // 检查是否有选中的行
{
DataGridViewRow row = dataGridView1.SelectedRows[0]; // 获取第一行
dataInfo = new 用户基本信息
{
No = yhbh.Text = row.Cells[0].Value.ToString(),
Name = yhmc.Text = row.Cells[1].Value.ToString(),
Password = yhmm.Text = row.Cells[2].Value.ToString(),
Dept = bm.Text = row.Cells[3].Value.ToString(),
Job = textBox11.Text = row.Cells[4].Value.ToString(),
Nation = zw.Text = row.Cells[5].Value.ToString(),
Birthday = dateTimePicker1.Text = row.Cells[6].Value.ToString(),
Phone = dh.Text = row.Cells[7].Value.ToString(),
Mail = yx.Text = row.Cells[8].Value.ToString()
};
}
```
该代码片段首先检查是否有选中的行,然后获取第一行,并将其数据赋值给 `dataInfo` 对象和窗体上的文本框。注意,这里使用了对象初始化器来构造 `dataInfo` 对象。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)