从对象和对象中检索将其分配给变量问题... [英] Retrieving from Object & assigning it to variable problem...

查看:74
本文介绍了从对象和对象中检索将其分配给变量问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

我在c#桌面应用程序中有一个类"Employee",BusinessLayer方法"Blayer.GetEmployeeDetails"和一个PresentationLayer.

我需要从表示层检索员工详细信息才能显示它.

Hi there.

I have a class ''Employee'', BusinessLayer method ''Blayer.GetEmployeeDetails'' and a PresentationLayer in a c# desktop application.

I need to retrieve the employee details from the presentation layer in order to display it.

Employee emp = new Employee(); //Calling the class 
Object empDetails = Blayer.GetEmployeeDetails(
(string)name, (string)surname, (string)roleType); //Calling the business layer method
string empName = emp.Name; //Adding employee name into string
label1.Text = empName; //Displaying in user interface



当我运行该应用程序时,结果返回"null".
我尝试调试,发现正确的信息在``empDetails''中,但是当我尝试将对象分配给变量时,例如
字符串empName = empDetails.Name;
然后我得到一个错误.

任何帮助都可以...

谢谢



When i run the app, the results return ''null''.
I tried debugging and saw that the correct information is in ''empDetails'' but when i try to assign the object to the variable e.g
string empName = empDetails.Name;
then i get an error.

Any help would do...

Thanks

推荐答案

empDetails必须是Blayer.GetEmployeeDetails方法的返回类型,而不是Object.
empDetails needs to be of the return type of the Blayer.GetEmployeeDetails method not Object.


嘿,伙计,请在业务层中使用方法的返回类型或使用var:
hey dude, use the return type of the method in the business layer or use var:
var empDetails = Blayer.GetEmployeeDetails(
(string)name, (string)surname, (string)roleType);

如果它不起作用,请尝试进入业务层,原因可能是那里发生了错误

if it doesn''t work, try stepping into the business layer cause maybe the error is happening there


尝试此
Employee emp = new Employee(); //Calling the class 
emp  = Blayer.GetEmployeeDetails(
(string)name, (string)surname, (string)roleType); //Calling the business layer method
string empName = emp.Name; //Adding employee name into string
label1.Text = empName; //Displaying in user interface


这篇关于从对象和对象中检索将其分配给变量问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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