草庐IT

send_this_email

全部标签

c# - VB 与 C# : Why is this possible?

这里有一些代码,每当我想到它时都会困扰我。OptionStrictOnModuleModule1SubMain()ForEachiAsIntegerInNewString(){"why","is","this","tolerated?"}'compilesjustfine.NextEndSubEndModuleC#根本不允许将字符串隐式转换为整数。classProgram{staticvoidMain(string[]args){foreach(intiinnewstring[]{"that's","better"}){//willnotcompile,andforgoodreason

C# HttpClient.SendAsync 在测试某些 URL 时抛出 "An error occurred while sending the request"异常

我正在开发一个C#控制台应用程序来测试URL是否有效或有效。它适用于大多数URL,并且可以从目标网站获得带有HTTP状态代码的响应。但是在测试其他一些URL时,应用程序会在运行HttpClient.SendAsync方法时抛出“发送请求时发生错误”异常。所以我无法获得任何响应或HTTP状态代码,即使这个URL实际上在浏览器中有效。我很想知道如何处理这个案子。如果URL不起作用或服务器拒绝我的请求,它至少应该给我相应的HTTP状态代码。以下是我的测试应用程序的简化代码:usingSystem;usingSystem.Net.Http;usingSystem.Threading.Tasks

c# - 为什么 `this` 在 C# 6.0 自动属性初始化中不可用?

我有以下代码类:publicclassFoo{publicNestedBar{get;}=newNested(this);publicclassNested{publicNested(Foofoo){foo.DoSomething();}}privatevoidDoSomething(){}}但是,我得到了这个编译错误:Keyword'this'isnotavailableinthecurrentcontext我可以通过简单地不使用自动属性初始化器来修复它,而是显式地将它移到构造函数中:publicNestedBar{get;}publicFoo(){this.Bar=newNeste

c# - 无效操作异常 : Cannot create a DbSet for 'Role' because this type is not included in the model for the context

以下解决方案适用于.netcore1.1,但从1.1升级到2.0后,我收到以下错误:InvalidOperationException:CannotcreateaDbSetfor'Role'becausethistypeisnotincludedinthemodelforthecontext.当用户尝试登录并执行以下语句时:varresult=await_signInManager.PasswordSignInAsync(model.Email,model.Password,model.RememberMe,lockoutOnFailure:false);怎么了?User.cspubl

c# - "T @this"在委托(delegate)声明中是什么意思?

我刚刚使用DustinCampbell'sWeakEventclass向项目添加了一个弱事件实现.虽然盲目地使用我在互联网上找到的代码™通常不是一个好主意,但它比我以前一起破解的要好得多。到目前为止它似乎运行良好,但为了理解代码,我遇到了以下问题:publicclassWeakEventHandler:IWeakEventHandlerwhereT:classwhereE:EventArgs{privatedelegatevoidOpenEventHandler(T@this,objectsender,Ee);...我习惯于仅使用objectsender和EventArgsargs参数

适用于 Windows 的 Docker 桌面 : No hypervisor is present on this system

我是DockerDesktopforWindows的新手。当我按照this尝试helloworld示例时出现错误。更新以下是我遵循的步骤:1InstalledDockerforWindows,stableversion2BothHyper-VandVirtualizationhavebeenenabledonmyWindows10但是,切换到Linux容器时出现以下错误:Anerroroccurred.HardwareassistedvirtualizationanddataexecutionprotectionmustbeenabledintheBIOS.Seehttps://doc

适用于 Windows 的 Docker 桌面 : No hypervisor is present on this system

我是DockerDesktopforWindows的新手。当我按照this尝试helloworld示例时出现错误。更新以下是我遵循的步骤:1InstalledDockerforWindows,stableversion2BothHyper-VandVirtualizationhavebeenenabledonmyWindows10但是,切换到Linux容器时出现以下错误:Anerroroccurred.HardwareassistedvirtualizationanddataexecutionprotectionmustbeenabledintheBIOS.Seehttps://doc

C# 何时使用 "This"关键字

这个问题在这里已经有了答案:关闭12年前。PossibleDuplicate:Whendoyouusethe“this”keyword?您好,我知道This关键字用于引用类的实例,但是,假设我有一个名为Life的类,它定义了两个字段,person(他们的名字)和他们的搭档(他们的名字):classLife{//Fieldsprivatestring_person;privatestring_partner;//PropertiespublicstringPerson{get{return_person;}set{_person=value;}}publicstringPartner{g

c# - Visual Studio 打包 : Another version of this product is already installed

我为使用C#和Jscript的项目创建了一个msi。version-1.0目前是公开的。我想发布此软件包的错误修复版本v-1.0.1,但在对其进行测试时,我收到“已安装此产品的另一个版本无法继续安装此版本。要配置或删除此产品的现有版本产品,使用控制面板上的添加/删除程序”。我希望这个错误修复版本静默安装,而不要求用户卸载并安装新版本。请帮助我如何实现这一目标,我正在使用visualstudio2008。提前致谢!山姆更新:我曾尝试更改包代码,但使用相同的工作目录创建了包的两个实例。VisualStudio极客们请帮忙。 最佳答案 我

c# - 将 "this"作为参数传递是一种不好的做法吗?

我目前很想写下以下内容:publicclassClass1(){publicClass1(){MyProperty=newClass2(this);}publicClass2MyProperty{get;privateset;}}publicclassClass2(){publicClass2(Class1class1){ParentClass1=class1;}publicClass1ParentClass1{get;set;}}将“this”作为参数传递是设计问题的标志吗?什么是更好的方法? 最佳答案 不,传递this没有根本的