在声明 paymentstatus 是否为空或在“if”语句中具有值时,我收到未分配变量“ps”的错误使用。我在想我已经宣布 ps 但显然我做错了什么。为什么编译器会抱怨这个?
这是它的上下文中的错误:
public IList<BestsellersReportLine> DailyBestsellersReport()
{
OrderStatus os;
PaymentStatus? ps;
ShippingStatus ss;
int billingCountryId = 0;
int recordsToReturn = 999;
int orderBy = 1;
int groupBy = 1;
int? paymentStatusId = null;
if (ps.HasValue)
paymentStatusId = (int)ps.Value;
// Specifies the time range for sold products/day
var range = new
{
startTimeUtc = DateTime.Today.AddDays(-1),
endTimeUtc = DateTime.Today.AddSeconds(-1),
CreatedOnUtc = DateTime.Today.AddDays(-1),
};
var query1 = from opv in _opvRepository.Table
join o in _orderRepository.Table on opv.OrderId equals o.Id
join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id
join p in _productRepository.Table on pv.ProductId equals p.Id
where (o.CreatedOnUtc >= range.startTimeUtc && o.CreatedOnUtc <= range.endTimeUtc) &&
(!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId)
select opv;
}
谢谢!