草庐IT

delete-operator

全部标签

c# - 为什么 is-operator 会导致不必要的装箱?

documentation与is运算符(exprisconstant)的常量模式匹配状态:Theconstantexpressionisevaluatedasfollows:Ifexprandconstantareintegraltypes,theC#equalityoperatordetermineswhethertheexpressionreturnstrue(thatis,whetherexpr==constant).Otherwise,thevalueoftheexpressionisdeterminedbyacalltothestaticObject.Equals(expr,

c# - 如何实现异步 File.Delete/Create/Move?

由于我必须在我的应用程序中进行大量文件I/O操作,我决定异步实现它们。查看MSDN,没有File.Create、File.Delete和File.Move的异步副本。据我了解,原因是不存在用于文件删除、创建或移动的异步Win32实现,所以我最终得到以下解决方案:publicstaticTaskDeleteAsync(stringpath){Guard.FileExists(path);returnTask.Run(()=>File.Delete(path));}publicstaticTaskCreateAsync(stringpath){Guard.IsNotNullOrWhites

c# - 无法使用 EFCore、EntityState.Modified : "Database operation expected to affect 1 row(s) but actually affected 0 row(s)." 编辑数据库条目

我将IdentityCore1.0与ASP.NETMVCCore1.0和EntityFrameworkCore1.0结合使用来创建一个简单的用户注册系统thisarticle作为起点,我正在尝试添加用户角色。我可以添加用户角色,但无法编辑它们。这是RolesController中的Edit操作:[HttpPost][ValidateAntiForgeryToken]publicIActionResultEdit(IdentityRolerole){try{_db.Roles.Attach(role);_db.Entry(role).State=Microsoft.EntityFrame

c# - 在泛型函数中使用重载的 operator==

考虑以下代码:classCustomClass{publicCustomClass(stringvalue){m_value=value;}publicstaticbooloperator==(CustomClassa,CustomClassb){returna.m_value==b.m_value;}publicstaticbooloperator!=(CustomClassa,CustomClassb){returna.m_value!=b.m_value;}publicoverrideboolEquals(objecto){returnm_value==(oasCustomCla

c# - "The binary operator Add is not defined for the types ' System.String ' and ' System.String '."-- 真的吗?

尝试运行以下代码时:Expression>stringExpression=Expression.Lambda>(Expression.Add(stringParam,Expression.Constant("A")),newList(){stringParam});stringAB=stringExpression.Compile()("B");我收到标题中提到的错误:“二元运算符Add没有为类型‘System.String’和‘System.String’定义。”真的是这样吗?显然在C#中它有效。在C#中执行strings="A"+"B"是表达式编译器无法访问的特殊语法糖吗?

c# - 在 Directory.Delete 之后,Directory.Exists 有时会返回 true 吗?

我的行为很奇怪。我有,Directory.Delete(tempFolder,true);if(Directory.Exists(tempFolder)){}有时Directory.Exists返回true。为什么?可能是资源管理器打开了吗? 最佳答案 Directory.Delete调用WindowsAPI函数RemoveDirectory.记录观察到的行为:TheRemoveDirectoryfunctionmarksadirectoryfordeletiononclose.Therefore,thedirectoryisnot

c# - 什么更快 : Regex or string operations?

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭9年前。我什么时候应该在字符串操作上使用正则表达式,反之亦然,仅考虑性能?

c# - .mdf"failed with the operating system error 2(系统找不到指定的文件。)

protectedvoidregister_Click(objectsender,EventArgse){AddUser(userName.Text,password.Text,confirm.Text);}voidAddUser(stringname,stringpass,stringconfirm){Useru=newUser(name,pass,confirm);if(u.Valid){using(vardb=newSiteContext()){db.User.Add(u);db.SaveChanges();}}}}publicclassUser{publicintUserId{

c# - checkin : Operation not performed Could not find file *. csproj.vspscc

由于我对项目和解决方案进行了一些更改,所以我在checkin代码文件时遇到了问题。我重命名了项目文件,在解决方案中添加了不同的项目文件,并在现有项目中添加了许多文件。现在我在检查代码时遇到错误。错误详情如下:CheckIn:OperationnotperformedCouldnotfindfile'....Console.csproj.vspscc'.如果vsspcc文件不是自己创建的,我该如何创建它?任何帮助都将非常有用,在此先感谢。 最佳答案 这对我来说看起来很愚蠢。我重新启动了我的VisualStudio,我可以执行check

c# - 填充数据集时 ODP.net Oracle 十进制数精度问题。异常 : Arithmetic operation resulted in an overflow

我正在使用c#.net2(VisualStudio2005SP1)尝试使用来自Oracle10g数据库的select*from表的结果填充数据集。.net框架、IDE和数据库无法在此客户端站点进行更改。我正在使用ODP.net提供商进行连接,dll版本是2.102.2.20当我运行填充命令时出现异常:算术运算导致溢出此外,如果我尝试在VisualStudio设计器(显示表数据)中查看有问题的列,我会为表中该列的每一行获取。如果我的查询选择其他带有整数的列(例如省略此列),则代码可以完美运行。当我在Toad的数据库中查看时,有问题的列看起来很好,数据如下:919.742866695572