private void createButton()
{
flowLayoutPanel1.Controls.Clear();
for (int i = 0; i < 4; i++)
{
Button b = new Button();
b.Name = i.ToString();
b.Text = "Button" + i.ToString();
flowLayoutPanel1.Controls.Add(b);
}
}
private void button1_Click(object sender, EventArgs e)
{
createButton();
}
Run Code Online (Sandbox Code Playgroud)
我使用此代码在运行时创建一些按钮,现在我如何使用这些创建的按钮执行不同的操作?我很新,所以请帮助我,非常感谢:)
问题我输入y
一个选项,它会在再次提示我之前打印文本两次,因为它应该只打印一次.
正确的输出(我应该得到但没有获得):
Do you order FISH (Y/N)? y
Fish choice (K- Haddock, T- Halibut)
Do you order FISH (Y/N)? y
Fish choice (K- Haddock, T- Halibut)
Do you order FISH (Y/N)? n
Do you order CHIPS (Y/N)? n
Do you order DRINKS (Y/N)? y
Drinks choice (S- Softdrink, C- Coffee, T- Tea)
Do you order DRINKS (Y/N)? n
Run Code Online (Sandbox Code Playgroud)
错误的输出(我得到的输出)
Do you order FISH (Y/N)? y
Fish choice (K- Haddock, T- Halibut)
Do you order FISH …
Run Code Online (Sandbox Code Playgroud) 我有一个数组作为类的成员.在子类中,我想重新定义具有不同大小的数组.我想这样做是因为我期望制作许多子类,每个子类只需要它所需的数组大小,仅此而已.
class Foo
{
Foo() {ivar = 1};
int thisArray[2];
int ivar;
}
class Bar : public Foo
{
Bar() {ivar = 3};
int thisArray[4];
}
int main()
{
Foo myFoo;
Bar myBar;
Foo fooCollection[] = {myFoo,myBar};
cout << "myFoo array size = " << sizeof(myFoo.thisArray)/sizeof(int) << endl;
cout << "myBar array size = " << sizeof(myBar.thisArray)/sizeof(int) << endl;
for (int n=0;n<2;n++)
{
cout << "fooCollection[" << n << "] array size = ";
cout << sizeof(fooCollection[n].thisArray)/sizeof(int) << endl;
} …
Run Code Online (Sandbox Code Playgroud) 我是C的全新人,并且在C编程语言书中有这个例子:
#include <stdio.h>
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
/* count line and words and characters in input */
main()
{
int c, nl, nw, nc, state;
state = OUT;
nl = nw = nc = 0;
while ((c = getchar()) != EOF) {
++nc;
if (c == '\n')
++nl;
if ( c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if ( …
Run Code Online (Sandbox Code Playgroud) 这是有bash
问题的陈述:
xx="$(echo 'a_b' | tr '_' '\t')"
Run Code Online (Sandbox Code Playgroud)
为什么下划线用空格而不是标签取代?
我有一个简单的问题,我做了一些研究,但找不到合适的答案.
我有这个字符串:
|她想吃早餐|
我找到了|
用另一个角色替换所有角色的答案.
我的想法是,我想,以取代第一|
与{
最后一个用}
.
我知道这很容易,但我对这个问题的答案真的会帮助我.
提前致谢.
我知道我可以使用foreach
循环,如下所示:
List<int> handles = GetHandles();
foreach (int handle in handles)
{
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
SortedList
我可以对 a执行以下操作吗?
SortedList<string, int> namesAndHandles;
Run Code Online (Sandbox Code Playgroud)
编辑:抱歉,打错字了。它应该是一个SortedList
. 本质上我想将其转换为 anIDictionary
并根据名称访问句柄
如果我有一个清单:
['12 13 0 21 0.3','2 3 0 1 0.1','12 19 0 2 0.9','22 33 0 3 0.5']
Run Code Online (Sandbox Code Playgroud)
如何删除每个元素的最后一部分的所有内容,以便列表变为:
['0.3','0.1','0.9','0.5']
Run Code Online (Sandbox Code Playgroud) 我有一个这样的方法
public ArrayList<T> GetDoctorDetail(String name)
{
if (name!=null || !name.isEmpty() || name!="")
{
//Statements
}
}
Run Code Online (Sandbox Code Playgroud)
但是在eclipse中!下划线用黄色线表示显示空指针访问:变量名在此位置只能为null.
为什么?什么是解决方案.
对不起,这是一个基本问题,但我的所有研究都几乎没有回答我的问题,我只是想在我编写所有代码之前仔细检查.我正在使用C,我有一个头文件,其中声明了一些变量(int
s,char
数组,int
数组).如果我有一个使用这些全局变量的函数,我假设我可以使用变量而不传递它们?
示例头文件:
int state;
int lnArray[];
Run Code Online (Sandbox Code Playgroud)
C文件:
void function(){
int i;
for(i=0;i<5;i++;){
if(lnArray[i]<10)
state = lnArray[i];
}
}
Run Code Online (Sandbox Code Playgroud)