Exam UiADPv1 All QuestionsBrowse all questions from this exam
Question 86

Considering that the attached data table is stored in a variable called “dt”:

Which of the following expressions will throw an exception during execution?

    Correct Answer: D

    The expression dt.AsEnumerable.First(Function(x)x(“Item”).ToString.Equals(“strawberry”)) will throw an exception. This is because the 'First' method is used to return the first element of a sequence that satisfies a specified condition. If no such element exists, it throws an InvalidOperationException. Since there is no item called “strawberry” in the provided data table, this expression will trigger an exception. The other methods ('Where', 'Any', and 'FirstOrDefault') either return an empty collection, a Boolean value, or a default value respectively, and thus will not throw an exception.

Discussion
kingkayyOption: D

A. It will return an empty collection. B. It returns true or false so it will be false in this case. C. It can return its default, which could be null in this case. D. The operation will be invalid.