理解接口和类的差异. [英] undersatnding interface and class diferences.

查看:75
本文介绍了理解接口和类的差异.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void DepartmentName_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            try
            {
                ((ITransaction)AppVariables.automator.AccountObj).DepartmentID = WebFormHelper.GetAccountIDFromName(DepartmentName.Text, AccountType.departmentMaster);
                ((ITransaction)AppVariables.automator.AccountObj).DepartmentName = DepartmentName.Text;
            }




在上面的代码中,我不明白为什么我们采用了(ITransaction),它称为/意味着(返回类型或其他任何东西)吗?
因为我已经在接口ITransaction中将属性声明为DepartmentID和DepartmentName并在Class Transaction中实现了它.

另外,我们可以在上面的代码段中使用Transaction而不是ITransaction吗?我试过了,它对我有用,但是,没有得到正确的答案(ITransaction或Transaction).




In above code i didnt get why we have taken (ITransaction),what it called/means(return type or anything else)??
as i have declared properties as DepartmentID and DepartmentName in interface ITransaction and implemented it in Class Transaction.

also, can we take Transaction instead of ITransaction in above snippet? i tried this, it works for me but , didnt get what will be correct there(ITransaction or Transaction).

推荐答案

(ITransaction)是强制转换-它正在转换任何AccountObj对象都可以放入实现(ITransaction)的对象实例中,而无需从原始对象类派生任何其他gubbins.不知道AccountObj可以返回什么,很难解释更多.

我们可以在上面的代码段中使用Transaction而不是ITransaction吗?"

不知道.由于我们不知道AccountObj返回什么,更不用说Transaction和ITransaction之间的关系了!
(ITransaction) is a cast - it is converting whatever the AccountObj object is into an instance of an object implementing (ITransaction) without any other gubbins the original object class may derive from. Without knowing what AccountObj can return, it is difficult to explain more.

"can we take Transaction instead of ITransaction in above snippet?"

No idea. Since we have no idea what AccountObj returns, much less the relationship between Transaction and ITransaction we can''t have a clue!


这篇关于理解接口和类的差异.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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