Select (keyword)
From The Oxygene Language Wiki
This is a Language topic
Feel free to add your notes to this topic below.
Sometimes it might be desirable to work with sequences that only contain a subset of the fields available in the original set, or contain additional fields calculated at runtime.
This can be achieved using the select clause, which allows you to specify a new set of data to be returned for each element in your sequence.
For example:
var list := from c in MyCustomers select new class(c.Name, c.City, Age := DateTime.Now-c.DateOfBirth);
This would return a sequence of a new (anonymous) class type containing only the Name, City and Age fields. The last field would be calculated by subtracting the date of birth from the current date, to obtain the age.
The above select statement will automatically create an anonymous class with the appropriate fields, and is basically a shorthand for "select new class (c.Name, c.City, Age := DateTime.Now-c.DateOfBirth)".
In addition to selecting a list of values, you can also select a single value, to obtain a sequence of that type. For example, simply writing "select c.Name" would return a new "sequence of String", while "select new CustomerInfo(c)" would create a new CustomerInfo class instance, and return a "sequence of CustomerInfo".
See Also
Area: Oxygene Language
Compiler version: Oxygene 5
Language Glossary — Keywords — Types — FAQ — How To