我想從一個單獨的程序中提取一個日期,並用它來確定合同的到期日期。我已經在一天和一年中調用了int的值,然後使用DateTime分配給另一個變量。轉換類型int的問題?整數缺少演員?
我對C#相當陌生,而且無法找到解決此塊所帶來錯誤的解決方法。錯誤告訴我它不能隱式轉換int? int,當我使用int? var聲明當天的月份和年份,然後將錯誤向下移動到DateTime行。
這可能需要結構不同,但我無法弄清楚這將是什麼。
private Instrument m_instr = null;
private void m_getInstrDetails(Instrument instr)
{
m_ContractName = instr.Name.ToString();
m_type = instr.Product.Type.ToString();
m_prod = instr.Product.ToString();
m_SmallestTickIncrtement = instr.InstrumentDetails.SmallestTickIncrement;
//month calc
int month = m_instr.InstrumentDetails.ExpirationDate.Month;
int day = m_instr.InstrumentDetails.ExpirationDate.Day;
int year = m_instr.InstrumentDetails.ExpirationDate.Year;
m_expDate1 = new DateTime(year, month, day);
那麼想必'ExpirationDate.Month'的類型是'爲int?','不是的int'性能。沒有'[mcve]'很難說。 (我們不知道'Instrument'類型是什麼,一開始。) –
如果值爲null,你會發生什麼? – Servy
請提供'Intrument'和'InstrumentDetails'定義。 – bradbury9