C# conditional lambda instead of if statements. Value cannot be null error -
i error: system.argumentnullexception: value cannot null. point right? if .freeamount null should check in amountlist selected amount. fails doing so. can't see have done wrong here.
var amount = string.isnullorempty(formmodel.freeamount) ? formmodel.amountlist .where(x => x.selected) .select(a => a.value) .singleordefault() : formmodel.freeamount;
you system.argumentnullexception in code posted if both freeamount , amountlist null. if there other default value want use in case, like:
var amount = string.isnullorempty(formmodel.freeamount) ? formmodel.amountlist == null ? "default value if freeamount , amountlist null" : formmodel.amountlist .where(x => x.selected) .select(a => a.value) .singleordefault() : formmodel.freeamount; otherwise, if want return null in case (which suppose more likely, since that's possibility singleordefault) can use null-conditional operator (?.):
var amount = string.isnullorempty(formmodel.freeamount) ? formmodel.amountlist? // <-- '?' return null if amountlist null .where(x => x.selected) .select(a => a.value) .singleordefault() : formmodel.freeamount;
Comments
Post a Comment