public partial class Route : Form
{
public List<string> picCount = new List<string>();
public Route(string statusInfo)
{
InitializeComponent();
this.listBox1.Focus();
this.statusInfo = statusInfo;
}
}public class ThreadWithState
{
public void ThreadProc()
{
//这边报错, 没用0个参数
Route r = new Route("");
//请问这边该怎么改?
r.picCount...
}
}
求解决方法
{
this.ID = Id;
this.Title = title;
}
public int ID { get; set; }
public int CategoryID { get; set; } public string Title { get; set; }
public string Summary { get; set; }
public string Alias { get; set; }
public string Content { get; set; }
public DateTime CreateTime { get; set; } public Category Category { get; set; }
public ICollection<Tag> Tags { get; set; }
public ICollection<Comment> Coments { get; set; }
}
Post post=new Post(1,"title")
public gouzao();你那是构造。
{
public Post(int Id,string title)
{
this.ID = Id;
this.Title = title;
} public int ID { get; set; }
public int CategoryID { get; set; } public string Title { get; set; }
public string Summary { get; set; }
public string Alias { get; set; }
public string Content { get; set; }
public DateTime CreateTime { get; set; } public Category Category { get; set; }
public ICollection<Tag> Tags { get; set; }
public ICollection<Comment> Coments { get; set; }
}Post post=new Post(1,"title")
如果是这样Application.Run(new Route());会报错 改成 Application.Run(new Route(""));
方法一,在Program中的入口实例化构造函数就必须传参: static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Route());
}
}方法二:
public partial class Route : Form
{
public List<string> picCount = new List<string>();
public Route(string statusInfo)
{
InitializeComponent();
this.listBox1.Focus();
this.statusInfo = statusInfo;
}
}public class ThreadWithState
{
public void ThreadProc()
{
//这边报错, 没用0个参数
Route r = new Route("");
//请问这边该怎么改?
r.picCount...
}
}类Route中没有默认的构造函数引起的,只要添加默认的构造函数就可以了。
{
InitializeComponent();
this.listBox1.Focus();
this.statusInfo = statusInfo;
}
自定义构造函数后,当进行实例化时通过该构造函数对其进行初始化,构造函数所带参数也要在相应位置赋值。例: public Route(string statusInfo,int intIndex){} 实例化时Route GetRoute=new Route("open",0) 。参数不能空缺。不知道说得对不对,有误请指正。