所以我有4个类:Employee(基类),PartTime:Employee,FullTime:Employee,Manager:Employee。我试图访问唯一但无法确切知道如何访问。我尝试过铸造但是没有用。这是我到目前为止所拥有的。
/autonomy/toshi/zero_mq.pyc in __init__(self, port, filt)
22 def __init__(self,port=None,filt=None):
23 super(ZeroMQ,self).__init__(self)
---> 24 self.port = port
25 self.filt = filt
26
//anaconda/lib/python2.7/site-packages/zmq/sugar/attrsettr.pyc in __setattr__(self, key, value)
24 except AttributeError:
25 raise AttributeError("%s has no such option: %s" % (
---> 26 self.__class__.__name__, upper_key)
27 )
28 else:
AttributeError: ZeroMQ has no such option: PORT
在此示例中,Manager具有BonusEarned,Department和OfficeLocation属性,但Employee,FullTime和PartTime不具备。
答案 0 :(得分:2)
试试这个(注意括号):
((Manager)emp1).BonusEarned = Convert.ToDecimal(txtBonus.Text);
((Manager)emp1).Department = comboDepartment.SelectedText;
((Manager)emp1).OfficeLocation = txtOffice.Text;
答案 1 :(得分:1)
if (emp1 is Manager)
{
var man = (Manager)emp1
man.BonusEarned = Convert.ToDecimal(txtBonus.Text);
man.Department = comboDepartment.SelectedText;
man.OfficeLocation = txtOffice.Text;
}