以下两种情况有什么区别:
class Data
{
PersonDataContext persons = new PersonDataContext();
public Data() {}
}
相对
class Data
{
PersonDataContext persons;
public Data()
{
persons = new PersonDataContext();
}
}
我在 asp.net 中有同样的问题:
public partial class Data : System.Web.UI.Page
{
PersonDataContext persons = new PersonDataContext();
protected void Page_Load(object sender, EventArgs e)
{
}
}
相对
public partial class Data : System.Web.UI.Page
{
PersonDataContext persons;
protected void Page_Load(object sender, EventArgs e)
{
persons = new PersonDataContext();
}
}