草庐IT

use-mirrors

全部标签

c# - 如何在vscode中禁用Unnecessary Using of Directive的警告?

我目前正在使用VS代码和Unity开发我的游戏。每次我打开编辑器,都会有99+Unnecessaryusingof指令,这让我很不爽。由于第三方插件有很多依赖性,我不确定是否可以删除它们。所以我想有一些方法来禁用它们。我试过类似的方法:"csharp.lint.unnecessaryUsingDirective":"ignore"但很明显,这是行不通的。所以我希望我能做些什么来隐藏或禁用此警告。 最佳答案 我觉得这个issuehasalreadybeenaddressed在最新版本的Omnisharp中——但由于我们被迫为Unity

c# - 从 using 语句中修改值类型是未定义的行为吗?

这个真的是thisquestion的一个分支,但我认为它应该得到自己的答案。根据ECMA-334的第15.13节(关于using语句,以下称为resource-acquisition):Localvariablesdeclaredinaresource-acquisitionareread-only,andshallincludeaninitializer.Acompile-timeerroroccursiftheembeddedstatementattemptstomodifytheselocalvariables(viaassignmentorthe++and--operators

c# - 使用 Reflection.Emit 发出 "using (x) { ... }" block ?

我正在尝试在C#中使用Reflection.Emit来发出using(x){...}block。在我编写代码时,我需要获取当前栈顶,它是一个实现了IDisposable的对象,将其存储在一个局部变量中,在该变量上实现一个usingblock,然后将其放入其中添加更多代码(我可以处理最后一部分。)这是我尝试编译并在Reflector中查看的示例C#代码片段:publicvoidTest(){TestDisposabledisposable=newTestDisposable();using(disposable){thrownewException("Test");}}这在Reflect

c# - 在 Using block 中调用 Environment.Exit()

如果我有一个代码如下的控制台应用程序:using(DisposableObjectobject=newDisposableObject()){if(acondition)Environment.Exit(0);//DoStuff}我的元素会被妥善处置吗?还是线程在对象被清理之前就死了? 最佳答案 您的应用程序将终止,所有托管内存将在此时释放。生成的finallyblock不会执行,所以任何Dispose方法都不会被调用,所以任何非托管资源都不会被释放。参见Don'tBlindlyCountonaFinalizer.

c# - 为什么此 XAML 收到错误 : Items collection must be empty before using ItemsSource

任何人都可以从这段代码中联想到为什么ItemsSource行会得到一个ItemscollectionmustbeemptybeforeusingItemsSource.错误?我发现的大多数解决方案都指向错误组合的XAML,例如我似乎没有的额外元素等。当我拿出来的时候ItemsSource="{BindingCustomers}"它运行没有错误(但当然不会显示我的客户列表)。Customers在ViewModel中这样定义,其中有3个CustomerViewModels:Customer[]customers=Customer.GetCustomers();IEnumerablecust

c# - 在代码中使用 '"using"关键字时,我应该在哪里捕获异常?

哪个在结构上更好?classProgram{staticvoidMain(string[]args){try{using(Foof=newFoo()){//somecommandsthatpotentiallyproduceexceptions.}}catch(Exceptionex){Console.WriteLine(ex.Message);}}}或者...classProgram{staticvoidMain(string[]args){using(Foof=newFoo()){try{//somecommandsthatpotentiallyproduceexceptions.

c# - "Both use the XML type name X, use XML attributes to specify a unique XML name and/or namespace for the type"怎么解决?

我有以下枚举定义...namespaceItemTable{publicenumDisplayMode{Tiles,Default}}namespaceEffectiveItemPermissionTable{publicenumDisplayMode{Tree,FullPaths}}...然后我有以下类(class)...publicclassTablewhereTDisplayMode:struct{//publicpublicTDisplayModeDisplayMode{get{returnmDisplayMode;}set{mDisplayMode=value;}}//pri

c# - 是否有必要将 usings 与 IDisposable 对象嵌套在一起?

我是否必须将所有IDisposable对象包装在using(){}语句中,即使我只是将一个对象传递给另一个对象?例如,在下面的方法中:publicstaticstringReadResponse(HttpWebResponseresponse){stringresp=null;using(StreamresponseStream=response.GetResponseStream()){using(StreamReaderresponseReader=newStreamReader(responseStream)){resp=responseReader.ReadToEnd();}}

c# - 将 using 语句放入命名空间失败

我正在尝试使用stylecop正确设置一些旧代码的样式。它要求将using语句放入其中。有效除了一个人以外,所有人都很好。我已将问题简化为以下代码。namespaceB.C{usingSystem;publicclassHidden{publicvoidSayHello(){Console.WriteLine("Hello");}}}namespaceA.B.C{usingB.C;publicclassProgram{staticvoidMain(string[]args){newHidden().SayHello();}}}这给出了编译错误Error"Thetypeornamespa

c# - 如何: Use async methods with LINQ custom extension method

我有一个LINQ自定义扩展方法:publicstaticIEnumerableDistinctBy(thisIEnumerableitems,Funcproperty){returnitems.GroupBy(property).Select(x=>x.First());}我是这样使用它的:varspc=context.pcs.DistinctBy(w=>w.province).Select(w=>new{abc=w}).ToList();但问题是我不想要ToList()我想要这样的东西varspc=awaitcontext.pcs.DistinctBy(w=>w.province).