想一次实现初始化多个实例 用意如下 但不知道正确应该怎么实现有videoa和videob两个类if(myselect == "videoa")
{
for(int i = 0; i < 2; i++)
{
videoa myva[i] = new videoa();
}
}
else
{
//myselect == "videob")...
}public void go(string myselect)
{
for(int i = 0; i < 2; i++)
{
myselect[i].Location = new System.Drawing.Point(0, 0);
}
}
{
for(int i = 0; i < 2; i++)
{
videoa myva[i] = new videoa();
}
}
else
{
//myselect == "videob")...
}public void go(string myselect)
{
for(int i = 0; i < 2; i++)
{
myselect[i].Location = new System.Drawing.Point(0, 0);
}
}
public void go(string myselect)
{
[myselect]0.Location = new System.Drawing.Point(0, 0);
[myselect]1.Location = new System.Drawing.Point(10, 0);}
错误 2不能在变量声明中指定数组大小(请尝试使用“new”表达式初始化)
类型[] 数组名 = new 类型[数组长度];
你要命名?videoa myva[i] = new videoa();--------->myva+i
if(myselect == "videoa")
{
for(int i = 0; i < 2; i++)
{
videoa myva(i) = new videoa();
}
}
if(myselect == "videoa")
{
for(int i = 0; i < 2; i++)
{
myva[i] = new videoa();
}
}
myv[1] 改成这样也不行~
for (int i = 0; i < 2; i++)
{
Work threadWork = new Work();
a[i] = new Thread(new ThreadStart(threadWork.DoWork));
a[i].Start();
}
videoa[] a = new videoa[5];
for(int i=0;i<5;i++)
{
a[i] = new videoa();
}
多谢 第一个问题解决了 呵呵再帮帮忙看下第二个问题public void go(string myselect)
{
for(int i = 0; i < 2; i++)
{
myselect[i].Location = new System.Drawing.Point(0, 0);
}
}
传入的是个字符串,哪来的Location属性?
{
for(int i = 0; i < 2; i++)
{
myselect(i).Location = new System.Drawing.Point(0, 0);
}
}myselect 为类名Location属性 是所有类的共有的属性 我想把所有控件调整显示的位置不论用哪个控件 调整位置的方法都是一样的 所以想写成一个
{
c.Location = new System.Drawing.Point(0, 0);
}
//
public void go(Control a[5])
{
for(for (int i = 0; i < 5; i++))
{
a[i].Location = new System.Drawing.Point(0, 0);
}
}
多个对像怎么处理呀?
{
foreach(Control c in ctrls)
c.Location = new System.Drawing.Point(0, 0);
}
//
mygo(myv);
//
public void go(Control a)
{
for(for (int i = 0; i < 5; i++))
{
a[i].Location = new System.Drawing.Point(0, 0);
}
}
//
多个对像怎么处理呀?
加控件啊 这么写吧
private void button1_Click(object sender, EventArgs e)
{
TextBox txt = null;
for (int i = 0; i < 5; i++)
{
txt = new TextBox();
txt.Width = 100;
txt.Name = "text"+i.ToString();
txt.Text = "我是大灰狼";
txt.Top = 50 * i;
//txt.TextChanged += new EventHandler(txtVa_TextChanged);
//在这可以加事件 然后事件中写逻辑
this.Controls.Add(txt); }
}
你还可以考虑下反射(System.Reflection)里面的相关的