Note that there are some explanatory texts on larger screens.

plurals
  1. POPros & cons between LINQ and traditional collection based approaches
    primarykey
    data
    text
    <p>Being relatively new to the .net game, I was wondering, has anyone had any experience of the pros / cons between the use of LINQ and what could be considered more traditional methods working with lists / collections? </p> <p>For a specific example of a project I'm working on : a list of unique id / name pairs are being retrieved from a remote web-service.</p> <ul> <li>this list will change infrequently (once per day), </li> <li>will be read-only from the point of view of the application where it is being used</li> <li>will be stored at the application level for all requests to access</li> </ul> <p>Given those points, I plan to store the returned values at the application level in a singleton class.</p> <p>My initial approach was to iterate through the list returned from the remote service and store it in a NameValueCollection in a singleton class, with methods to retrieve from the collection based on an id:</p> <pre><code>sugarsoap soapService = new sugarsoap(); branch_summary[] branchList = soapService.getBranches(); foreach (branch_summary aBranch in branchList) { branchNameList.Add(aBranch.id, aBranch.name); } </code></pre> <p>The alternative using LINQ is to simply add a method that works on the list directly once it has been retrieved:</p> <pre><code>public string branchName (string branchId) { //branchList populated in the constructor branch_summary bs = from b in branchList where b.id == branchId select b; return branch_summary.name; } </code></pre> <p>Is either better than the other - is there a third way? I'm open to all answers, for both approaches and both in terms of solutions that offer elegance, and those which benefit performance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload