jjzjj

collection

全部标签

c# - 无法使用集合初始值设定项实现类型 XYZ,因为它不实现 'System.Collections.IEnumerable'

我有以下类(class):publicclassCommentList{stringItemType;stringComment1;stringStatus1;stringDiscussionBoardId;GuidCourseId;GuidCommentID;}我正在尝试执行以下LINQ语句:Listquery=fromcindb.Commentsjoinsindb.Statusonc.StatusIdequalss.StatusIdjoindindb.DiscussionBoardsonc.DiscussionBoardIdequalsd.DiscussionBoardIdwher

c# - 我可以遍历 Collection.Request.Form 吗?

我有一些具有唯一ID的复选框。是否可以在一个表单集合中找到所有的checkbox+uniquenum?有点像-foreach(variteminCollection.Request.Form["checkbox"+withUniqueIDNum]){//code} 最佳答案 没有。相反,您可以遍历所有键,并检查它们是否以checkbox开头。例如:foreach(stringkeyinRequest.Form){if(!key.StartsWith("checkbox"))continue;...}NameValueCollecti

c# - 取消订阅 observableCollection 中的事件

假设我有一个observableCollection类:CustomClassNametestClass=newCustomClassName();ObservableCollectioncollection=newObservableCollection();testClass.SomeEvent+=OnSomeEvent;collection.add(testClass);当我要从集合中删除项目时,我需要手动取消订阅事件(OnSomeEvent)还是应该留给GC?退订的最佳方式是什么? 最佳答案 如果您希望收集您的元素,那么是的

c# - 使用 DelegatingHandler 配置 Swashbuckle 作为消息调度程序

我有一个WebAPI,它是一个非常薄的基础架构,只包含两个DelegatingHandler实现,它们将传入消息分派(dispatch)到业务层中定义的消息处理程序实现。这意味着没有Controller,也没有Controller操作;API仅基于消息定义。这意味着在实现新功能时不需要更改此基础架构层中的代码。例如,我们有这样的消息:创建订单命令ShipOrderCommandGetOrderByIdQueryGetUnshippedOrdersForCurrentCustomerQuery委托(delegate)处理程序根据url确定确切的消息,并将请求内容反序列化为该消息类型的实例

c# - 第三方库中麻烦的 GC.collect() 调用

在分析我的应用程序(C#、.NET4)时,我注意到我正在使用的第三方库显式调用了GC.Collect()。这非常烦人,因为它有时会对我的应用程序性能产生巨大影响,因为对该库的一些调用最终会陷入巨大的循环:花在GC.Collect上的时间占总执行时间的80%以上。当然,我向库维护者报告了这种行为(库不是开源的),但是当他们正在开发新版本时,我想优化我的应用程序。我能做什么?我尝试通过将GCSettings.LatencyMode设置为GCLatencyMode.LowLatency来配置GC(当然,仅在执行库调用期间),但无济于事。我宁愿避免fork我的过程。有什么想法吗?

c# - 使用反射在 C# 中设置索引属性的值

我有一个类有一个ObservableCollection作为属性,我正在尝试更改该类实例的该属性内的值。这是我的代码,它会引发TargetException:object[]index=null;varoriginalPropertyName=propertyName;if(propertyName.Contains("[")&&propertyName.Contains("]")){index=newobject[1];index[0]=Convert.ToInt32(propertyName.Split('[')[1].Split(']')[0]);propertyName=pro

c# - .NET 4.0 System.Collections.Concurrent 集合在 .NET 3.0 SynchronizedCollection 的功能中添加了什么?

.NET4.0引入了System.Collections.Concurrent命名空间:"TheSystem.Collections.Concurrentnamespaceprovidesseveralthread-safecollectionclassesthatshouldbeusedinplaceofthecorrespondingtypesintheSystem.CollectionsandSystem.Collections.Genericnamespaceswhenevermultiplethreadsareaccessingthecollectionconcurrentl

c# - 具有泛型的对象类型中的 "apostrophe + number"是什么意思(例如 "Collection` 1")?

我有一个对象(MyObject)和一个属性(MyProperty)。我想获取它的类型名称(即String或MyClass等)。我使用:PropertyInfopropInfo=typeof(MyObject).GetProperty("MyProperty");Console.WriteLine(propInfo.PropertyType.Name);Console.WriteLine(propInfo.PropertyType.FullName);简单类型没问题,但当MyProperty是通用类型,我在获取它的名称时遇到问题(例如Collection)。它打印:Collection`

c# - 将 ListView 的 SelectedItems 绑定(bind)到 ViewModel

我有一个ListView,它将项目与View模型中的属性绑定(bind)。在View模型中。ICollectionView_businessCollectionpublicICollectionViewBusinessCollection{get{return_businessCollection;}set{_businessCollection=value;RaisePropertyOnChange("BusinessCollection");}}如何在View模型中获取选中的businesscollection项? 最佳答案 1

c# - 检查 Collection 中的所有项目是否具有相同的值

名为MeasurementCollection的集合的扩展方法检查每个项目的属性Template.Frequency(Enum)是否具有相同的值。publicstaticboolIsQuantized(thisMeasurementCollectionitems){return(fromiinitemsselecti.Template.Frequency).Distinct().Count()==1;}编辑关于底层类的信息MeasurementCollection:ICollectionIMeasurement{IMeasurementTemplateTemplate{get;}...