在System.Collections.ObjectModel中似乎也有某些集合類。這兩個命名空間下的集合與我們在哪種情況下應該使用System.Collections.ObjectModel有什麼區別?System.Collections VS System.Collections.ObjectModel
5
A
回答
6
從MSDN:
的System.Collections.ObjectModel 命名空間包含的類可以用作可重複使用的庫的對象模型 集合 。當屬性或方法 返回集合時,請使用這些 類。
0
一個明顯的區別是,System.Collections.ObjectModel
命名空間包含通用 只讀集合(即,沒有添加,刪除和清除方法等)。
0
System.Collections.ObjectModel類將您的集合暴露給外部世界很有用。 (通過外部世界,我的意思是代碼不會與您的代碼一起版本)
因此,在您的代碼中使用泛型集合類,但是要將其包含在Collection,ReadOnlyCollection或ObservableCollection中,以便將其暴露給外部世界。
要將集合包裝爲鍵控集合,可以將KeyedCollection用作幫助器的基類。
相關問題
- 1. System.Collections.Generic vs System.Collections?
- 2. 即使使用'System.Collections.ObjectModel'
- 3. 泛型和System.Collections
- 4. System.Collections.ObjectModel收集<T>
- 5. 在System.Collections中找不到ArrayList類型
- 6. System.Collections - 爲什麼有這麼多選項?
- 7. 在沒有System.Collections的情況下創建堆棧類
- 8. .NET中的System.Collections,System.Collections.Specialized和System.Collections.Generic有什麼區別?
- 9. 爲什麼C#的System.Collections庫中沒有ReadOnlyList <T>類?
- 10. 如何返回System.Collections程序集中的名稱空間列表?
- 11. Xamarin Studios找不到System.Collections的參考資料?
- 12. System.Collections是「System命名空間的命名空間」嗎?
- 13. 如何在Xamarin.Forms便攜式項目中使用System.Collections
- 14. 使用System.Collections輸入參數錯誤F中的隊列類#
- 15. System.Collections散列表 - 搜索最近添加的匹配
- 16. PowerShell的哈希表不寫入預期文件 - 只接收「System.Collections中」行
- 17. vs vs 2008 vs vs 2010
- 18. Exec的VS ExecWait VS ExecShell VS nsExec :: Exec的VS nsExec :: ExecToLog VS nsExec :: ExecToStack VS ExecDos VS ExeCmd
- 19. FTP vs SFTP vs HDFS vs NTFS vs EXT2,EXT3
- 20. VS VS VS VS 11中的MVC測試
- 21. CGL vs AGL vs OpenGL vs NSOpenGL vs CoreAnimation(CALayer)
- 22. MobileNet VS SqueezeNet VS ResNet50 VS啓V3 VS VGG16
- 23. NTOSKRNL.EXE VS NTKRNLMP.EXE VS NTKRNLPA.EXE VS NTKRPAMP.EXE
- 24. VS 2008 vs VS 2008 Express
- 25. RailwayJS vs Geddy vs Express vs Socket.IO
- 26. .NET vs ASP.NET vs CLR vs ASP
- 27. DynamicProperty vs MutableProperty vs AnyProperty vs ConstantsProperty
- 28. codendi vs redmine vs Retrospectiva vs trac
- 29. body.scrollTop VS documentElement.scrollTop VS window.pagYOffset VS window.scrollY
- 30. Asp.net vs Html5 vs xml vs xhtml