草庐IT

system-wide

全部标签

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# - 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

c# - 具有 System.Security.Claims 的 .NET Framework 中的复杂声明值

我正在开发一个使用Asp.Net5MVC、Owin和Oauth2不记名token作为身份验证类型的网络应用。在thisguide添加自定义复杂声明Json并成功序列化到Microsoft.IdentityModel.Claims.ClaimsIdentity实例之后,我尝试使用System.Security.Claims命名空间上的ClaimsIdentity复制相同的示例。不幸的是,似乎在complexClaim实例中添加了一个ClaimsIdentity,派生类的类型信息丢失了,声明存储为一个System.Security.Claims.Claim。varcomplexClaim=

c# - 为什么用于 Unicode 属性测试的 C# System.Char 方法有两个重载?

在methodsofSystem.Char,我们看到两种检查字符是否为符号的方法:publicstaticboolIsSymbol(strings,intindex)publicstaticboolIsSymbol(charc)同样适用于其他属性测试:IsLower、IsLetter等为什么会出现这种重复?有什么理由比Char.IsSymbol(s[idx])更喜欢Char.IsSymbol(s,idx)吗? 最佳答案 从表面上看,这两个重载在功能上似乎是相同的,但是深入到对InternalGetUnicodeCategory的调用

c# - 使用 System.ComponentModel.DataAnnotations.Validator 验证属性

我的实体设置为DataAnnotation验证属性,我正在尝试使用静态Validator对其进行验证类,但我得到不同的异常,这不是正确的方法吗:string_ValidateProperty(objectinstance,stringpropertyName){varvalidationContext=newValidationContext(instance,null,null);validationContext.MemberName=propertyName;varvalidationResults=newList();varisValid=Validator.TryValida

c# - 将 System.Windows.Media.ImageSource 转换为 System.Drawing.Bitmap

如何在C#中将System.Windows.Media.ImageSource转换为System.Drawing.Bitmap? 最佳答案 它是较旧的OP,但对于其他一些人来说仍然可以派上用场,因为在没有dll互操作或剪贴板hack的情况下找到更干净的解决方案需要一些时间。这对我有用,您可以在保存到文件或rtf流之前使用pngencoder来削减图像大小privateSystem.Drawing.ImageImageWpfToGDI(System.Windows.Media.ImageSourceimage){MemoryStrea

c# - SmtpClient 和 app.config system.net 配置

我在开发用于发送电子邮件的.NET3.5库时遇到问题。我将system.net配置放入app.config:然后我在没有参数的情况下实例化SmtpClient:SmtpClientclient=newSmtpClient();但是配置没有被读取(我试图用NUnit测试库)并且我得到一个System.InvalidOperationException,因为配置没有被读取,因此主机为空。不应该自动读取配置吗? 最佳答案 确保将配置block(如上所示)添加到{appName}.exe.config或web.config-类库的配置是在运