c# - C# 使用 messagebox.show 在一行中存储和显示计算的迭代
问题描述
我正在研究这个程序。我的目的是将计算的输入数据的结果存储在一个 int[] 变量中,并使用 messagebox.show 在一行中显示。
int[] data = new int[] { 65, 66, 67, 32, 100, 90 }; // I declare int[] data it contain my data that I want to work with the length change.
int[] array = new int[6]; // i declare a table length of 6
foreach (var b in data) // for every element in my data I want to do this operations and build my array.
{
array[0] = b / 200;
array[1] = b / 79;
array[2] = b / 27;
array[3] = b / 19;
array[4] = b / 21;
array[5] = b / 3;
Console.WriteLine("{0}", string.Join(" ", array)); // this line is for console application
// output of this line is :
/*
0 0 2 3 3 21
0 0 2 3 3 22
0 0 2 3 3 22
0 0 1 1 1 10
0 1 3 5 4 33
0 1 3 4 4 30 */
MessageBox.Show(" "+ string.Join(" ", array)); // this line is for windowsform application
我的目的是在 windowsform 应用程序中使用 messagebox.show 显示我的变量。我的目标是将它们存储在一个变量中并像这样显示它们:
0 0 2 3 3 21 0 0 2 3 3 22 0 0 2 3 3 22 0 0 1 1 1 10 0 1 3 5 4 33 0 1 3 4 4 30
我真的很感激任何帮助。
亲切的问候
解决方案
您可以简单地将字符串加入循环中,然后在消息框中的循环之外显示它们。使用StringBuilder
类追加结果。
StringBuilder sb = new StringBuilder();
for(...)
{
...
...
sb.AppendFormat("{0} ", string.Join(" ", array).Trim())
}
MessageBox.Show(sb.ToString());
推荐阅读
- google-analytics - Google GA 不跟踪基于事件的目标
- python - 计算回合中回归的均方根误差
- node.js - 终端中的 npm 错误和警告
- java - ClassCastException:com.sun.proxy.$ProxyX 无法转换为类
- kubernetes - kubectl 不适用于多个集群配置
- javascript - 如果可以在 WebSocket javascript 中将数据作为纯文本发送,为什么我需要对数据进行屏蔽和框架化?
- android - 我如何将秒表值传递给另一个活动
- mysql - 两种方式都唯一的主键对
- php - 修改 Wordpress 搜索功能时内存大小耗尽
- python-3.x - IterativeImputer 错误:输入包含 NaN、无穷大或对于 dtype('float64') 来说太大的值