Is it possible to do something like this?
var strings = ConfigurationManager.ConnectionStrings;
var names = (from d in strings
select new ConnectionName(d.Name));
Is it possible to do something like this?
var strings = ConfigurationManager.ConnectionStrings;
var names = (from d in strings
select new ConnectionName(d.Name));
Yes, but because
ConnectionStrings
does not implement a strongly typedIEnumerable
, you have to tell LINQ what type the collection contains.Use either
from ConnectionStringSettings d in strings
orConfigurationManager.ConnectionStrings.Cast<ConnectionStringSettings>()
.You can loop with a foreach:
You have to Cast it to its type as it is
IEnumerable
notIEnumerable<T>
See Enumerable.Cast :