不明白为什么这不起作用 [英] Dont understand why this does not work

查看:80
本文介绍了不明白为什么这不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常简化:


名称空间人类


{


公共类main2:系统.Web.UI.Page


{


公共DataSet员工


{


get


{


退货员工;


}


set


{


员工=价值;

}


........


然后从用户控件访问Employee:


humanres.main2.Employee但它(员工)不在那里。


我很困惑。


可以请一些,请解释我错过了什么?

Very simplified:

namespace humanres

{

public class main2 : System.Web.UI.Page

{

public DataSet Employee

{

get

{

return Employee;

}

set

{

Employee = value;

}

........

Then to access Employee from the user control:

humanres.main2.Employee but it''s (Employee) not there.

I am very confused.

Can some please, please explain what am I missing?

推荐答案

您需要一个存放DataSet对象的地方。请尝试以下方法:


namepace humanres

{

公共类main2:System.Web.UI.Page

{

私有DataSet _Employee = null;


公共DataSet员工

{

获得

{return _Employee;}

set

{_Employee = value;}

}

}

}


这样,DataSet就会存储在对象的某个地方。请记住,属性是变量的访问器,可以设置变量并获取变量。你需要一个单独的变量来实际存储对象。在示例代码中,我刚刚在名称中添加了一个下划线,但它可能是任何名称都不重要的东西,只是get重新定义了一个实际变量,并且该集合能够设置一些变量。

希望这会有所帮助,

马克菲茨帕特里克

微软MVP- FrontPage


" Mark Goldin" <毫安******** @ comcast.net>在留言新闻中写道:%2 **************** @ tk2msftngp13.phx.gbl ...

非常简化:

名称空间人类


{


公共类main2:System.Web.UI.Page

{


公共数据集员工


{


get


{


退货员工;


}


设置


{


员工=价值;


}

.......


然后从用户控件访问Employee:


humanres.main2.Employee但它(员工)不在那里。


我很困惑。


有人可以,请解释我错过了什么?

You need a place to store the DataSet object. Try the following:

namepace humanres
{
public class main2 : System.Web.UI.Page
{
private DataSet _Employee = null;

public DataSet Employee
{
get
{return _Employee;}
set
{_Employee = value;}
}
}
}

That way the DataSet is getting stored somewhere in the object. Remember, a property is an accessor for a variable that enables setting the variable, and getting the variable. You need a seperate variable somewhere to actually store the object. In the sample code I just added an underscore to the name, but it could be anything as the name is not important, just that the get reuturns an actual variable and the set is able to set some variable.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP- FrontPage

"Mark Goldin" <ma********@comcast.net> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Very simplified:

namespace humanres

{

public class main2 : System.Web.UI.Page

{

public DataSet Employee

{

get

{

return Employee;

}

set

{

Employee = value;

}

.......

Then to access Employee from the user control:

humanres.main2.Employee but it''s (Employee) not there.

I am very confused.

Can some please, please explain what am I missing?


嗯,你的例子有点太简单但是......

员工是你的main2类的一个属性在humanres名称空间中。 Employee是一个实例属性,而不是静态属性。我甚至不认为humanres.main2.Employee会编译。


从你的用户控件,你可以做到


DataSet ds = ((humanres.main2)页).Employee;


Page是你的main2类的实际实例。


按你自己的方式去做,你会做的


public static DatSet Employee {

get {return Employee; }

set {Employee = value; }

}


但我大约95%肯定这不是你想要的,也不会像你期望的那样表现。


另外,我认为这只是一个错字,但是你的财产员工的获取器会自行返回,这将产生明显的副作用....


Karl


-

我的ASP.Net教程
http://www.openmymind.net/

" Mark Goldin" <毫安******** @ comcast.net>在留言新闻中写道:%2 **************** @ tk2msftngp13.phx.gbl ...

非常简化:

名称空间人类


{


公共类main2:System.Web.UI.Page

{


公共数据集员工


{


get


{


退货员工;


}


设置


{


员工=价值;


}

.......


然后从用户控件访问Employee:


humanres.main2.Employee但它(员工)不在那里。


我很困惑。


有人可以,请解释我错过了什么?

Well, your example is a little too simple but...
Employee is a property of your main2 class located in the humanres namespace. Employee is an instance property, as opposed to a static propery. I wouldn''t even think humanres.main2.Employee would compile.

From your user control, you could do

DataSet ds = ((humanres.main2)Page).Employee;

Page is the actual instance of your main2 class.

Do do it your way, you''d do

public static DatSet Employee{
get { return Employee; }
set { Employee = value; }
}

but I''m about 95% sure that isn''t what you want and will not behave as you expect.

Also, I imagine it''s just a typo, but your property "Employee"''s get accessor returns itself, which will have viscious side-effects....

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mark Goldin" <ma********@comcast.net> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Very simplified:

namespace humanres

{

public class main2 : System.Web.UI.Page

{

public DataSet Employee

{

get

{

return Employee;

}

set

{

Employee = value;

}

.......

Then to access Employee from the user control:

humanres.main2.Employee but it''s (Employee) not there.

I am very confused.

Can some please, please explain what am I missing?


如何从用户控件访问Employee?


" Mark Fitzpatrick" <毫安****** @ fitzme.com>写在消息

新闻:eB ************** @ tk2msftngp13.phx.gbl ...

你需要一个地方存储DataSet对象。请尝试以下方法:


namepace humanres

{

公共类main2:System.Web.UI.Page

{

私有DataSet _Employee = null;


公共DataSet员工

{

获得

{return _Employee;}

set

{_Employee = value;}

}

}

}


这样DataSet就会存储在对象的某个地方。

记住,a property是一个变量的访问器,可以设置

变量,并获取变量。你需要一个单独的变量

来实际存储对象。在示例代码中,我刚刚在名称中添加了一个下划线

,但它可能是任何名称都不重要的东西,只是

,get reuturns一个实际的变量和该套装可以设置一些

变量。


希望这会有所帮助,

Mark Fitzpatrick

Microsoft MVP- FrontPage


" Mark Goldin" <毫安******** @ comcast.net>在留言中写道

新闻:%2 **************** @ tk2msftngp13.phx.gbl ...

非常简化:


名称空间人类


{


公共类main2:System.Web.UI。页面


{


公共DataSet员工


{


get


{


退货员工;


}


set


{


员工=价值;


}


.......


然后从用户控件访问Employee:


humanres.main2.Employee但它的(员工)不在那里。


我很困惑。


可以一些请解释我错过了什么?
How am I accessing Employee from the user control?

"Mark Fitzpatrick" <ma******@fitzme.com> wrote in message
news:eB**************@tk2msftngp13.phx.gbl...
You need a place to store the DataSet object. Try the following:

namepace humanres
{
public class main2 : System.Web.UI.Page
{
private DataSet _Employee = null;

public DataSet Employee
{
get
{return _Employee;}
set
{_Employee = value;}
}
}
}

That way the DataSet is getting stored somewhere in the object.
Remember, a property is an accessor for a variable that enables setting the
variable, and getting the variable. You need a seperate variable somewhere
to actually store the object. In the sample code I just added an underscore
to the name, but it could be anything as the name is not important, just
that the get reuturns an actual variable and the set is able to set some
variable.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP- FrontPage

"Mark Goldin" <ma********@comcast.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Very simplified:

namespace humanres

{

public class main2 : System.Web.UI.Page

{

public DataSet Employee

{

get

{

return Employee;

}

set

{

Employee = value;

}

.......

Then to access Employee from the user control:

humanres.main2.Employee but it''s (Employee) not there.

I am very confused.

Can some please, please explain what am I missing?


这篇关于不明白为什么这不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆