Eventuali differenze?C#: Iterating through a data table: Rows, Select() o AsEnumerable()
risposta
Rows
non è fortemente tipizzato - così ci sarà un cast ad ogni iterazione, e non è possibile utilizzare LINQ agli oggetti su di esso facilmente. (Credo che lo stesso AsEnumerable()
inserirà internamente ogni iterazione, ma almeno lo si può usare facilmente per altri metodi LINQ.)
Select
ha bisogno di costruire un array, quindi c'è ovviamente una penalità di prestazioni lì.
Personalmente userei AsEnumerable()
a meno che non si voleva modificare la tabella all'interno del ciclo, nel qual caso il fatto che Select
costruisce una matrice up-front può effettivamente essere un vantaggio.
Utilizzare AsEnumerable() se si sta tentando di eseguire una query sul datatable utilizzando LINQ, altrimenti, si potrebbe anche utilizzare la struttura di looping ...
- 1. Iterating through array - java
- 2. Iterating through viewgroup
- 3. Iterating Through N Level Children
- 4. Rolling rows in SQL table
- 5. Iterating through all JDK classes
- 6. Iterating through Arraylist con classi estese
- 7. Rails ha_molto attraverso la query a seconda dell'attributo table through
- 8. PostgreSQL DELETE FROM (SELECT * FROM table FETCH FIRST SOLO 10 ROWS)
- 9. C++ Loop through Map
- 10. filter/select rows of pandas dataframe by timestamp column
- 11. SELECT richiede 100ms; CREATE table as select - o - INSERT in select take 15mins
- 12. Iterating su ember.js Ember-data Record Arrays
- 13. Come aggiungere una clausola where complessa a Zend Table Select?
- 14. Has_Many: Through o: finder_sql
- 15. jQuery loop through data() oggetto
- 16. Che è più veloce: "SELECT * FROM table" o "SELECT x, y, q FROM table" (da una tabella con 4 campi)
- 17. C#: Cycle through encodings
- 18. MySQL INSERT o SELECT
- 19. Iterating over a lvalue
- 20. delete rows ff package
- 21. Iterating on a tuple ... again
- 22. WPF Datagrid Cycle Through/Select Cells With Specific Property
- 23. Iterating over a map entryset
- 24. SQL View o Table
- 25. Table = Table vs Table.Data (Table)
- 26. Flattening Rows in Spark
- 27. Carattere strike-through nell'obiettivo C
- 28. Apache POI rows number
- 29. GridView rows outer margin
- 30. Understanding .AsEnumerable() in LINQ to SQL