Users Pricing

forum

Home Forums Understanding .Single() – MindStick

Understanding .Single()

Anonymous User 1968 23 Aug 2014

Browsing sample code I'm seeing a usage I don't understand:

var orderRow = order.Rows.Single();

Rows is an enumerable and usually one would iterate using a foreach loop. Is the .Single a workaround for cases where, for whatever reason, the foreach can't be (or need not) be used?

var option = options.OfType<AdditionalLocationsOption>().SingleOrDefault();

if (option != null){

...stuff

}


1 Answers

Sumit Kesarwani 23 Aug 2014 Accepted Answer
Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md