我有一个在 VB.NET 中编译的程序集,其中包含两个运算符:
Public Shared Operator =(quarterA As CalendarQuarter, quarterB As CalendarQuarter) As Boolean
Return quarterA.StartDate = quarterB.StartDate AndAlso
quarterA.EndDate = quarterB.EndDate AndAlso
quarterA.Quarter = quarterB.Quarter
End Operator
Public Shared Operator <>(quarterA As CalendarQuarter, quarterB As CalendarQuarter) As Boolean
Return Not (quarterA = quarterB)
End Operator
但是,当使用 C# 中的程序集执行相等检查时if (qtr != null)
,我收到错误:
Cannot implicitly convert type 'object' to 'bool'
在 C# MVC4、Razor 中的用法:
@{Html.BeginForm();}
<div class="ui-form ui-form-horizontal form-width-narrow">
<div class="title">
Choose a Quarter</div>
<div class="group">
<label><strong>Control</strong></label>
<div class="field">
@Html.DropDownListFor(x => x.Quarter, new SelectList(Model.AvailableQuarters))
<input value="Select" class="ui-button" type="submit" />
</div>
</div>
@if (Model.Quarter != null) {
// Error in the above statement
}
</div>
@{Html.EndForm();}
我需要做什么才能使相等运算符正常运行?