草庐IT

list_content

全部标签

c# - List<int> 需要很长时间才能使用 Nhibernate Criteria 进行实例化

我有这个查询,它返回7行并在数据库中花费4毫秒,但在实例化时花费1075毫秒。这只是时代的一个例子,它因对象而异,但花费这么长时间似乎没有意义。关于如何提高速度的任何指示?varcriteria=GetSession().CreateSQLQuery(@"selectcirct_idasCircuitIdfromnormal_upstreamwheredni_equip_type='A'startwithup_equip_stn_noin(:UpStationNo1)connectbypriorequip_stn_no=up_equip_stn_nounionselectcirct_i

c# - 如何对 List<T> 使用 BinarySearch

让我们从ListBinarySearch的重载开始:publicintBinarySearch(Titem,IComparercomparer);众所周知,在使用BinarySearch之前,应该使用适当的IComparer对列表进行排序。但是然后:要搜索列表,您将必须提供一个T项。当人们习惯于根据项目的属性搜索列表中的项目(即使用Linq或委托(delegate)/谓词)时,这是相当出乎意料的。因为当我已经有了我的T项目时,我就不需要搜索它了!现在我在C#中实现C++代码,看到C++程序员在他的代码中到处使用C++风格的二进制搜索,如下所示。首先他制作了一个新的Titem,并赋予了这

c# - HttpRequest.Content.IsMimeMultipartContent() 在应该返回 true 时返回 false

我需要将HTTP请求作为MultiPartFormData发送到RESTController。它正在工作,但现在我对我的Controller进行的检查声称请求的类型不正确,即使我可以在调试器中看到请求的类型正确。供引用:这是调用它的控制台应用程序代码:usingSystem;usingSystem.IO;usingSystem.Net.Http;usingSystem.Net.Http.Headers;usingSystem.Text;namespaceQuickUploadTestHarness{classProgram{staticvoidMain(string[]args){us

c# - Web Api 请求抛出 "Error while copying content to a stream."

我正在尝试实现这个codeexample,但得到一个HttpRequestException-“将内容复制到流时出错。”当调用ReadAsStringAsync()方法时。内部异常是“无法访问已处置的对象”。我正在使用Fiddler来发出请求。我不明白。有人可以解释为什么我会收到此异常并提供解决方案吗?网络API方法:publicasyncTaskPost(HttpRequestMessagerequest){try{varjsonString=awaitrequest.Content.ReadAsStringAsync();}catch(Exceptionex){throw;}ret

c# - List<Task> - 使用 C# Entity Framework 的 UPSERT 数据库记录

我有一个Employee对象,我正在尝试使用单个DB实体上下文使用多个任务(并行执行)来更新记录(即更新/删除)。但是我收到以下异常Message="Objectreferencenotsettoaninstanceofanobject."考虑以下DTOpublicclassEmployee{publicintEmployeeId{get;set;}publicstringFirstName{get;set;}publicstringLastName{get;set;}publicListContactPhoneNumbers{get;set;}publicListContactEma

c# - List<T>.Enumerator 的 Reset 方法的行为

以下两种方法(一种使用IEnumerator,另一种使用List.Enumerator)即使看起来相同会产生不同的结果。staticvoidM1(){varlist=newList(){1,2,3,4};IEnumeratoriterator=list.GetEnumerator();while(iterator.MoveNext()){Console.Write(iterator.Current);}iterator.Reset();while(iterator.MoveNext()){Console.Write(iterator.Current);}}staticvoidM2(){

c# - 将带有 List 的字典转换为 IEnumerable

我有一本字典:Dictionary>test=newDictionary>();然后我填充这个字典,因此我需要这个列表以便我可以调用Add()。我的问题是函数需要返回:Dictionary>有没有简单的方法可以做到这一点,而无需执行明显的操作并循环遍历我的原始字典并手动执行? 最佳答案 returndictionary.ToDictionary(x=>x.Key,x=>x.Value.AsEnumerable()) 关于c#-将带有List的字典转换为IEnumerable,我们在Sta

c# - 设置 "Always copy to output directory"时,Content 和 None 有什么区别?

在csproj文件中,我们可以使用None或Content元素包含一个文件。来自MSDN,它说:None-Thefileisnotincludedintheprojectoutputgroupandisnotcompiledinthebuildprocess.Anexampleisatextfilethatcontainsdocumentation,suchasaReadmefile.Content-Thefileisnotcompiled,butisincludedintheContentoutputgroup.Forexample,thissettingisthedefaultva

c# - IQueryable<T> 给出的结果与 List<T> 不同

如果我在我的EntityFramework结果中对IQueryable使用Select,我将得到4个项目。如果我在IQueryable.ToList()上使用Select,我会得到所有36个项目。函数代码如下:publicImagesGetModelViewGet(intstart,intcount){if(countImageHandler.MaxResult)count=ImageHandler.MaxResult;IQueryableimagesList=ImagesHandler.FetchRangeScore(start,count).Where(m=>m.Domain==D

c# - List<T>.Last() 是否枚举集合?

考虑List的边界是已知的,确实.Last()枚举集合?我问这个是因为documentation说它是由Enumerable定义的(在这种情况下,它将需要枚举集合)如果它确实枚举了集合,那么我可以简单地通过索引访问最后一个元素(正如我们所知的.Count的List),但必须这样做似乎很愚蠢。... 最佳答案 如果集合是IEnumerable,它会枚举集合而不是IList(对于数组或列表,将使用索引)。Enumerable.Last通过以下方式实现(ILSpy):publicstaticTSourceLast(thisIEnumera