小编omE*_*han的帖子

将字符串转换为按钮

我在图形winforms上创建了5个按钮(即:btn0,btn1,btn2,btn3,btn4)。我想用这些按钮填充数组。

以下代码正在运行:

Button[] btn = new Button[5];

for (int i=0; i<5; i++)
 Button[i] = new Button();

btn[0]=btn0;
btn[1]=btn1;
btn[2]=btn2;
btn[3]=btn3;
btn[4]=btn4;
Run Code Online (Sandbox Code Playgroud)

但是我希望能够在一个for循环内完成它(假设我有100个按钮)。这可能吗?

我尝试通过以下方式进行操作,但出现错误:

无法将类型'string'隐式转换为'System.Windows.Forms.Button'

Button[] btn = new Button[5];
for (int i=0; i<5; i++)
{
    btn[i] = new Button();
    btn[i] = "btn"+i.ToString():
}
Run Code Online (Sandbox Code Playgroud)

c# string button winforms

1
推荐指数
1
解决办法
1674
查看次数

'%'%'%' 是什么意思,为什么它等于 0?

以下程序:

int main()
{
    printf("%d", '%'%'%');
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

产生输出:

0
Run Code Online (Sandbox Code Playgroud)

我想知道这是什么原因。

c char modulo

1
推荐指数
1
解决办法
153
查看次数

带有 rand 的 Cpp 随机数返回非常相似的数字

我正在尝试使用 rand() 命令生成一个随机数,但每次我都会得到非常相似的数字。这是我的代码:

#include <iostream>
#include <time.h>
using namespace std;

int main()
{
    srand(time(0));
    cout << rand();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我跑了 5 次,得到的数字是:21767 21806 21836 21862 21888

我怎样才能使数字更加不同?

c++ random random-seed

1
推荐指数
1
解决办法
71
查看次数

标签 统计

button ×1

c ×1

c# ×1

c++ ×1

char ×1

modulo ×1

random ×1

random-seed ×1

string ×1

winforms ×1