score:5

Accepted answer

in general linq would be used to query information. in this case you're also querying the info.

what you could do however is the following:

dts.connections.foreach((conman) =>
{
    dts.events.fireinformation(0, "", string.format("connection manager {0} has connection string {1}", connman.name, connman.connectionstring), "", 0, ref fireagain);
}

that is, if dts.connections is a list, otherwise you can't do this. (can't tell from your question if it's an ienumerable or a list)

a workaround would be to create an extension method and the use it anyway. like this:

public void foreach<t>(this ienumerable<t> source, action<t> action)
{
    foreach(t item in source)
    {
        action(item);
    }
}

after that, you can use the foreach method on your source as shown in the example.

score:2

dts.connections
   .foreach(connman => dts.events.fireinformation(0, "", string.format("connection manager {0} has connection string {1}", connman.name, connman.connectionstring), "", 0, ref fireagain));

if connections is not a ienumerable, change first line with ;

dts.connections.tolist()

score:7

i would not suggest trying to convert this to linq, because linq is meant to be used for functional programming, not imperative. if you wanted to compare it to sql, then it would be without dml.

dts.events.fireinformation doesn't seem to return a value that you could select. it probably fires an event or something, and it also uses a ref parameter. that piece of code doesn't look like a query at all, and i think it shouldn't be forced into one. a foreach loop is perfectly fine in this case, as you're actually doing work inside it and not querying data (which is what linq would be for).

if you needed to filter a collection based on some condition, if you need to join separate collections or something like that, then linq might be a better tool for the job.


Related Query

More Query from same tag