jjzjj

c# - 删除不必要的命名空间(使用)指令是否有性能提升?

我的类中有多少using编译器指令重要吗?删除那些不必要的东西会提高性能吗?虽然我喜欢编写精简的代码,但有时代码段会被修改,并且没有机会返回并检查所有包含的命名空间是否真的有必要。或者,我不会返回并删除那些由VisualStudio自动插入的内容。即:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.Mvc;谢谢! 最佳答案 不,没有性能优势。编译器不会为using语句生成IL(可执行代码)。IL仅

c# - 如何在 Xamarin.forms 上播放声音?

我正在使用Xamarin.forms创建适用于Android、iOS和WindowsPhone的应用。我的问题是如何使用XamarinForms播放mp3或wav?我的业务逻辑由共享项目处理,我不知道如何使用特定平台“MediaPlayer”。 最佳答案 目前Xamarin.forms还没有完善的API,需要使用DependencyService检查以下链接,它对我来说工作正常:https://www.codeproject.com/Articles/1088094/Playing-audio-mp-File-in-Xamarin-

C# - 我无法引用 HttpPostedFileBase

我在带有CSLA的分布式环境中使用MVC.NET,我可以从我的网络层之一(例如Website.MVC)引用HttpPostedFileBase,但我不能从单独的层(我们称之为OtherLayer.Web)引用HttpPostedFileBase。知道我需要做什么才能调用HttpPostedFileBase吗?我可以在两个层中使用HttpPostedFile-我应该只使用它吗?程序集引用基本相同-在Website.MVC中我有:namespaceWebsite.Mvc.Controllers{usingSystem;usingSystem.Collections;usingSystem.

c# - 在 SQLDataReader 上使用

我知道我之前问过一个相关问题。我只是有另一个想法。using(SqlConnectionconn=newSqlConnection('blahblah')){using(SqlCommandcmd=newSqlCommand(sqlStatement,conn)){conn.open();//***doIneedtoputthisinusingaswell?***SqlDataReaderdr=cmd.ExecuteReader(){While(dr.Read()){//readhere}}}}论点是:由于SqlDataReaderdr对象不是像连接或命令对象那样的新对象,它只是指向c

c# - 在展开嵌套的 "Dispose"语句时处理 "using"抛出的异常

显然,在使用嵌套的using语句时,一些异常可能会丢失。考虑这个简单的控制台应用程序:usingSystem;namespaceConsoleApplication{publicclassThrowing:IDisposable{intn;publicThrowing(intn){this.n=n;}publicvoidDispose(){vare=newApplicationException(String.Format("Throwing({0})",this.n));Console.WriteLine("Throw:{0}",e.Message);throwe;}}classPr

c# - .NET 私​​钥 Rsa 加密

我需要使用RSA1.5算法加密字符串。我已获得私钥。但是,我终生无法弄清楚如何将此key添加到类(class)中。看起来key需要是RSAParameter结构类型。然而,这需要一组我没有给出的值,例如模数、指数、P、Q等。我所拥有的只是私钥。谁能帮忙? 最佳答案 你应该知道BouncycastleC#library.特别是有两个非常有用的类:Org.BouncyCaSTLe.OpenSsl.PemReader可以将您拥有的openssl样式key转换为bouncycaSTLekey对象,以及Org.BouncyCaSTLe.Sec

c# - WCF Web 服务错误 : "Service endpoint binding not using HTTP protocol"?

我有一个简单的WCF服务,在我的开发机器上测试时它运行良好。现在我已将Web服务移至Web服务器,并在http://mydomain.com:8005运行该服务(在Debug模式下).打开Web浏览器访问该URL会显示预期的服务页面,如果我在我正在调用的界面内的服务器上放置一个断点,它会命中断点并返回预期的数据......但在客户端它会返回出现以下错误:AnerroroccurredwhilereceivingtheHTTPresponsetohttp://mydomain.com:8005/.Thiscouldbeduetotheserviceendpointbindingnotus

c# - 实体类型需要定义主键

我现在正在编写一个ASP.NETWebAPI,对于2个Controller,一切都运行良好。现在我尝试做与以前完全相同的事情,但这次我得到一个奇怪的错误:System.InvalidOperationException:"Theentitytype'UserItem'requiresaprimarykeytobedefined."那么,为什么UserItem需要主键而其他的不需要?这是我的UserItem类:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Threading.Tasks;n

c# - 在 NUnit 参数化测试中找不到合适的构造函数

查看下面的测试夹具:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingNUnit.Framework;//////TestsrelatingtoHarryPotter///[TestFixture("Dumbledore")]publicclassHarryPotterTests{publicstringName;publicHarryPotterTests(stringpersonName){Name=personName;}[Test]publicvoidTest()

c# - 在 Using 语句中创建 ObjectContext 时出现 NullReferenceException

是时候再次吸引更伟大的思想了。我正在经历一个非常奇怪的现象。正如标题所述,我在尝试创建EFObjectContext时收到NullReferenceException,但只有在Using语句中创建上下文时才会收到异常。我尝试了各种不同的方法,但结果总是一样。而且,当然,这是直到昨天都运行良好的代码。我的Windows更新昨天早上运行可能与此相关。反正...如果我试试这个using(varcontext=newEntities(Env.Instance.Connection)){//doabunchofEFstuff}我在创建ObjectContext时收到NullReferenceEx