Hey Guys,
Im having trouble with DataStore... I have a method that return a list and sometimes it should return null. Thats good but when it should return null then i get an exception that value cannot be null![120724-image.png][1]
[1]: /answers/storage/attachments/120724-image.png
Anyone who knows why it cant return null?
Here is my code:
public async Task<List<Workouts>> GetWorkoutsAsync(string choosedDay, bool forceRefresh = false)
{
WorkoutDay = TodaysWorkout(choosedDay);
if (WorkoutDay != null)
return await Task.FromResult(WorkoutDay.workouts);
else
return null;
}
private WorkoutsByDay TodaysWorkout(string workoutday)
{
WorkoutsByDay test = null;
for(int i = 0; i < allWorkoutDays.Count(); i++)
{
if (test == null)
{
if (allWorkoutDays[i].WeekDay == workoutday)
{
test = allWorkoutDays[i];
}
else
{
test = null;
}
}
}
return test;
}
And here is where i call the method:
async Task TodaysWorkouts(string day)
{
var test = await DataStore.GetWorkoutsAsync(day, true);
}
If this one return null then i get the exception... But if it dosent return null then it works...