Elena Elena
Elena Elena

Reputation: 11

LINQ query does not "see" the values in array

here is my query

        var traj_of_user_2=
        from num in trajectoryArray
        where num.ID_User == 2
        select num.ID_Traj;

when i run the program, an exception appears (see the image)

what's the problem is your opinion? a friend of me told me that since the array is "lazy" there are no istances

enter image description here

Upvotes: 1

Views: 66

Answers (2)

Emmanuel N
Emmanuel N

Reputation: 7449

Only get ID_User when num != null

    var traj_of_user_2=
        from num in trajectoryArray
        where (num != null && num.ID_User == 2)
        select num.ID_Traj;

Upvotes: 0

Thom Smith
Thom Smith

Reputation: 14086

There is a null in the array, and num.ID_User is failing. You can filter out nulls like this:

var traj_of_user_2=
    from num in trajectoryArray
    where num != null &&
          num.ID_User == 2
    select num.ID_Traj;

Upvotes: 1

Related Questions