Reputation: 16330
Is it possible to do something like this?
var strings = ConfigurationManager.ConnectionStrings;
var names = (from d in strings
select new ConnectionName(d.Name));
Upvotes: 2
Views: 2828
Reputation: 31
You can loop with a foreach:
Just use the conn property you're looking for
foreach (var conn in ConfigurationManager.ConnectionStrings.Cast<ConnectionStringSettings>())
{
conn.Name
}
Upvotes: 3
Reputation: 62498
You have to Cast it to its type as it is IEnumerable
not IEnumerable<T>
See Enumerable.Cast :
Casts the elements of an IEnumerable to the specified type.
var t = from c in connectionString.Cast<System.Configuration.ConnectionStringSettings>()
select c.Name;
Upvotes: 0
Reputation: 28799
Yes, but because ConnectionStrings
does not implement a strongly typed IEnumerable
, you have to tell LINQ what type the collection contains.
Use either from ConnectionStringSettings d in strings
or ConfigurationManager.ConnectionStrings.Cast<ConnectionStringSettings>()
.
Upvotes: 12