草庐IT

system.diagnostics

全部标签

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# - 为什么我不能从 System.Enum 抽象类派生?

MSDN将System.Enum定义为一个抽象类:[SerializableAttribute][ComVisibleAttribute(true)]publicabstractclassEnum:ValueType,IComparable,IFormattable,IConvertible而且MSDN对抽象类也有这样的说法:Anabstractclasscannotbeinstantiated.Thepurposeofanabstractclassistoprovideacommondefinitionofabaseclassthatmultiplederivedclassescan

c# - 将字节数组从 Oracle RAW 转换为 System.Guid?

我的应用程序使用自定义数据访问层与Oracle和SQLServer数据库交互,使用DataReader以ADO.NET编写。现在我在GUID(我们将其用于主键)和OracleRAW数据类型之间进行转换时遇到问题。插入oracle很好(我只是在System.Guid上使用ToByteArray()方法)。当我从数据库加载记录时,问题是转换回System.Guid。目前,我正在使用从ADO.NET获得的字节数组传递到System.Guid的构造函数中。这似乎有效,但出现在数据库中的Guid与我以这种方式生成的Guid不对应。我无法更改数据库架构或查询(因为它被重新用于SQLServer)。

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

c# - 我应该用 TraceSource.TraceEvent 方法中的 id 参数来识别什么?

我使用TraceSource用于登录我的.NET项目的类。然而,我一直不清楚的一点是,TraceEvent中的id参数的意图是什么?方法。目前,我总是将它设置为0。但是它的预期用途或典型用途是什么?我能想到几种可能性:它是事件发生的ID(即同一行代码在每次执行时产生不同的ID);它是方法调用的ID(即您可以从ID推断代码行);它是一系列类似事件的ID(例如,表示数据库不存在的所有错误消息共享相同的ID);它是与逻辑操作相关的一组事件的ID,结合TraceEventType.(Start|Stop|Suspend|Resume|Transfer)枚举值; 最佳

c# - Process.Start() 什么时候可以返回 null?

我有一些代码通过使用Process.Start(ProcessStartInfo)来启动一个进程.我从文档中看到,如果重用现有流程,此方法可以返回null。[Returnsa]newProcesscomponentthatisassociatedwiththeprocessresource,ornullifnoprocessresourceisstarted(forexample,ifanexistingprocessisreused).重用现有流程意味着什么,在什么情况下会发生这种情况? 最佳答案 如果您调用pass一个文件(不是

c# - System.IO.Directory.GetFiles 空

当我枚举“C:\Windows\System32\Tasks”时,谁能解释为什么GetFile()为空?System.IO.Directory.GetFiles(@"C:\Windows\System32\Tasks");我检查过这个:VS以管理员身份运行没有抛出异常根目录下有文件我可以(通过资源管理器)将文件复制到另一个文件夹,而且它可以工作 最佳答案 这里的问题是您正在以x86运行程序,它是beingsilentlyredirectedtoanotherfolder里面没有文件。(它将被重定向到C:\Windows\SysWOW

c# - 创建随机颜色 (System.Drawing.Color)

我正在尝试创建随机绘图颜色。有一个错误。你能帮我看看这段代码吗?privateRandomrandom;privatevoidMainForm_Load(objectsender,EventArgse){random=newRandom();}privateColorGetRandomColor(){returnColor.FromArgb(random.Next(0,255),random.Next(0,255),random.Next(0,255));//Theerrorishere}publicSolidBrushbrushGet(){SolidBrushoBrush=newSo