This error is displayed when I enter this bold code snippet What are the drawbacks?(int)Course.SubGroup??0
public void OnGet(long id)
{
Course= _CourseApplication.GetCourse(id);
var groups = _CourseApplication.GetSarGroup();
ViewData["Groups"] = new SelectList(groups,"Value","Text",Course.GroupId);
var subGrous = _CourseApplication.GetSubGroup(long.Parse(groups.First().Value));
ViewData["SubGroups"] = new SelectList(subGrous, "Value", "Text",**(int)Course.SubGroup??0**);
This error is displayed error CS0019: Operator '??' cannot be applied to operands of type 'int' and 'int'
CodePudding user response:
The variable on the left side of ??
operator has to be nullable (which means that you can assign null to it), in your case Course.SubGroup
should be of type int?
not int
. And no need cast to int, change like below:
ViewData["SubGroups"] = new SelectList(subGrous, "Value", "Text",Course.SubGroup??0);