让我们继续说我有以下功能:publicclassTest{publicasyncTaskFinalize(){//Wedon'tneedthisinthisclass,soemptybody}/**Additionalmethodssnipped*/}虽然这工作得很好,但我会收到一条编译器警告:Thisasyncmethodlacks'await'operatorsandwillrunsynchronously.Considerusingthe'await'operatortoawaitnon-blockingAPIcalls,or'awaitTask.Run(...)'todoCPU
让我们继续说我有以下功能:publicclassTest{publicasyncTaskFinalize(){//Wedon'tneedthisinthisclass,soemptybody}/**Additionalmethodssnipped*/}虽然这工作得很好,但我会收到一条编译器警告:Thisasyncmethodlacks'await'operatorsandwillrunsynchronously.Considerusingthe'await'operatortoawaitnon-blockingAPIcalls,or'awaitTask.Run(...)'todoCPU
这可能是一个很好的观点,但它涉及编译器发出的警告,如果您执行以下操作:classA{publicvirtualvoidF(){}}classB:A{publicvoidF(){}}然后你会得到警告:'EomApp1.B.F()'hidesinheritedmember'EomApp1.A.F()'.Tomakethecurrentmemberoverridethatimplementation,addtheoverridekeyword.Otherwiseusethenewkeyword.问题:如果我不采取任何措施,实际警告我的警告是什么?如果我添加“new”关键字与不添加关键字,我的
这可能是一个很好的观点,但它涉及编译器发出的警告,如果您执行以下操作:classA{publicvirtualvoidF(){}}classB:A{publicvoidF(){}}然后你会得到警告:'EomApp1.B.F()'hidesinheritedmember'EomApp1.A.F()'.Tomakethecurrentmemberoverridethatimplementation,addtheoverridekeyword.Otherwiseusethenewkeyword.问题:如果我不采取任何措施,实际警告我的警告是什么?如果我添加“new”关键字与不添加关键字,我的
这应该是显而易见的,但我无法让它工作......我想做的很简单:如果有警告,我希望编译失败并报错。是的,著名的TreatWarningsAsErrors...我在我的C#项目属性中配置了它这会导致我的csproj中出现预期的TreatWarningsAsErrors部分:true到目前为止一切顺利,如果我在我的代码中添加一个无用的private变量,它会导致编译错误:privateintunused;Error3WarningasError:Thefield'XXXX.unused'isneverused但整个问题是,我无法使其适用于程序集引用问题。如果我有对未知程序集的引用,编译器(
这应该是显而易见的,但我无法让它工作......我想做的很简单:如果有警告,我希望编译失败并报错。是的,著名的TreatWarningsAsErrors...我在我的C#项目属性中配置了它这会导致我的csproj中出现预期的TreatWarningsAsErrors部分:true到目前为止一切顺利,如果我在我的代码中添加一个无用的private变量,它会导致编译错误:privateintunused;Error3WarningasError:Thefield'XXXX.unused'isneverused但整个问题是,我无法使其适用于程序集引用问题。如果我有对未知程序集的引用,编译器(
我有这个警告:Warning3Ambiguitybetweenmethod'Microsoft.Office.Interop.Word._Application.Quit(refobject,refobject,refobject)'andnon-method'Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit'.Usingmethodgroup.在我的线上wordApplication.Quit();我尝试将其替换为:wordApplication.Quit(false);//don'tsavechanges和wor
我有这个警告:Warning3Ambiguitybetweenmethod'Microsoft.Office.Interop.Word._Application.Quit(refobject,refobject,refobject)'andnon-method'Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit'.Usingmethodgroup.在我的线上wordApplication.Quit();我尝试将其替换为:wordApplication.Quit(false);//don'tsavechanges和wor
我有以下代码片段在VS2008中生成“如果有意隐藏则使用新关键字”警告:publicdoubleFoo(doubleparam){returnbase.Foo(param);}基类中的Foo()函数是protected,我想通过将它放在包装类中来将其暴露给单元测试,仅用于单元测试。IE。包装器类将不会用于任何其他用途。所以我的一个问题是:这是公认的做法吗?回到new警告。为什么我必须在这种情况下新建覆盖函数? 最佳答案 new只是绝对清楚地表明您知道自己正在践踏现有方法。由于现有代码是protected,这没什么大不了的——你可以安
我有以下代码片段在VS2008中生成“如果有意隐藏则使用新关键字”警告:publicdoubleFoo(doubleparam){returnbase.Foo(param);}基类中的Foo()函数是protected,我想通过将它放在包装类中来将其暴露给单元测试,仅用于单元测试。IE。包装器类将不会用于任何其他用途。所以我的一个问题是:这是公认的做法吗?回到new警告。为什么我必须在这种情况下新建覆盖函数? 最佳答案 new只是绝对清楚地表明您知道自己正在践踏现有方法。由于现有代码是protected,这没什么大不了的——你可以安