草庐IT

my_io_object

全部标签

c# - 为什么c#内置的IO类比自制的快?

当我决定在C#中自己实现JavaByteBuffer时,我认为它会比MemoryStream+BinaryWriter/二进制阅读器。我通过ILSpy查看了它们的源代码,发现有很多检查和辅助方法调用,而在我的实现中,我直接使用底层字节数组。但是,当测试表明重型内置类的方法调用比我的轻型方法调用快将近两倍时,我感到非常惊讶。例如:publicvoidWriteBytes(Byte[]buffer,Int32offset,Int32count){this.EnsureFreeSpace(count);Buffer.BlockCopy(buffer,offset,this.buffer,th

c# - 高级 : How to optimize my complex O(n²) algorithm

我有以下人员和地点数据:Person实体有IList每个都有IList可能的地方Schedule即日模式。10天可用4天不可用在特定的DateRangePlaces内日期范围必须遵守Schedule人是否可以去特定地方的模式。Place实体有IList每个定义每个日期范围内的开始/结束时间重叠的日期范围作为LIFO。因此,对于之前已经定义的每一天,新的时间定义优先。问题现在我需要做这样的事情(用伪代码):foreachPlace{foreachDaybetweenminimumandmaximumdateinIList{getasetofPeopleapplicableforPlace

c# - IsKeyboardFocusable 在 Inspect Object 中为 true 但在我的应用程序中始终为 false

我正在学习UIAutomation,我发现我的“InspectObject”克隆显示IsKeyboardFocusable始终为false,即使它是true,所有其他信息都是相同的(正如您从图片)。有谁知道为什么我在检索值时将此属性视为false? 最佳答案 在InspectObject应用程序中,最新版本的WindowsAutomationCOMAPI(3.0)用于显示所有这些属性。但是默认的.NETUIAutomation实现并不基于WindowsAutomationAPI3.0COM接口(interface)(它基于此COMA

c# - Large Object Heap Compaction,什么时候好?

首先,多大才算大?有没有办法确定一个对象在堆中有多大?.Net4.5.1带有此LargeObjectHeapCompactionMode:AftertheLargeObjectHeapCompactionModepropertyissettoGCLargeObjectHeapCompactionMode.CompactOnce,thenextfullblockinggarbagecollection(andcompactionoftheLOH)occursatanindeterminatefuturetime.YoucancompacttheLOHimmediatelybyusingc

c# - 如何使用 Moq 为接口(interface)模拟 `object.Equals(object obj)`

我有一个有趣的问题要解决。考虑像这样的一些接口(interface):publicinterfaceIMyThing{intId{get;}}现在我想测试使用这个接口(interface)的代码。也许有一些LINQ魔法。像这样:publicclassSomeClass{privateIMyThing_thing;...publicboolHasThing(IEnumerablethings){returnthings.Contains(_thing);}}我正在模拟所有实现IMyThing的对象使用Moq:publicstaticIMyThingMockMyThing(intnewId

c# - Linq 和相等运算符 : Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object'

我试图重写C#中的相等(==)运算符来处理任何类型与自定义类型的比较(自定义类型实际上是null周围的包装器/框)。所以我有这个:internalsealedclassNothing{publicoverrideboolEquals(objectobj){if(obj==null||objisNothing)returntrue;elsereturnfalse;}publicstaticbooloperator==(objectx,Nothingy){if((x==null||xisNothing)&&(y==null||yisNothing))returntrue;returnfal

c# - 运行所选代码生成器时出错 : 'Object reference not set to an instance of an object.' Error?

我已经尝试了所有解决方案,例如修复VS2013,但没有用。当您通过右键单击Controller文件夹创建Controller并添加Controller时,然后右键单击新创建的Controller的操作并选择添加View,当我尝试创建View时,它就发生了。这不是新项目,而是现有项目。 最佳答案 我在我的VS2017上遇到了这个问题,我通过这样做解决了它:转到C:\Users\username\AppData\Local\Microsoft\VisualStudio\15.0_7fca0c70,您将看到一个名为ComponentMod

C# System.Object.operator==()

我正在努力了解System.Object.operator==()的使用。我的EffectiveC#书和这里的页面(http://www.srtsolutions.com/just-what-is-the-default-equals-behavior-in-c-how-does-it-relate-to-gethashcode)说:“System.Object.operator==()将调用a.Equals(b)以确定a和b是否相等”。所以我的代码:objecta=1;objectb=1;if(object.Equals(a,b)){//Willgetherebecauseitcal

c# - 有人使用 .NET 的 System.IO.IsolatedStorage 吗?

我在阅读.NET中的System.IO.IsolatedStorage命名空间时发现我可以使用它来将文件存储到我的程序集或可执行文件的唯一位置。例如下面的代码:usingSystem.IO.IsolatedStorage;publicclassProgram{staticvoidMain(string[]args){IsolatedStorageFilestore=IsolatedStorageFile.GetUserStoreForAssembly();store.CreateFile("myUserFile.txt");}}在以下位置创建文件“myUserFile.txt”:C:\

c# - System.IO.File.Move--如何等待移动完成?

我正在用C#编写一个WPF应用程序,我需要移动一些文件——问题是我真的真的需要知道这些文件是否成功。为此,我写了一个检查以确保文件在移动后到达目标目录——问题是有时我在文件移动完成之前就进行了检查:System.IO.File.Move(file.FullName,endLocationWithFile);System.IO.FileInfo[]filesInDirectory=endLocation.GetFiles();foreach(System.IO.FileInfotempinfilesInDirectory){if(temp.Name==shortFileName){ret