草庐IT

is_derived_from_Wrap

全部标签

c# - 将 Generic<Derived> 转换为 Generic<Base>

这个问题在这里已经有了答案:CannotconvertfromListtoList(6个答案)InC#,whycan'taListobjectbestoredinaListvariable(14个答案)关闭1年前。我有一个基本的WPFUserControl,它处理派生的UserControl的一些常见功能。在任何派生的UserControl的代码隐藏中,我调用一个事件privatevoidSomeClick(objectsender,RoutedEventArgse){HandleClick(sender);MyDataGrid.Items.Refresh();}在我的基本UserCo

c# - MSDN : What is "Thread Safety"?

在许多MSDN文档中,这写在线程安全标题下;“此类型的任何公共(public)静态(在VisualBasic中为共享)成员都是线程安全的。不保证任何实例成员都是线程安全的。”例如;here有人可以用一种相当简单的方式解释一下吗?谢谢:) 最佳答案 埃里克·利珀特(EricLippert)表现出色blogpost对这个。基本上它本身有点毫无意义。当我看到那个样板时,就我个人而言,在这方面我不太相信MSDN。它并不总是意味着它所说的。例如,它对Encoding说了同样的话-尽管事实上我们都在各处使用来自多个线程的编码。除非我有任何理由不

c# - 数据库错误 : There is no row at position 0

我相信几个月前有人问过这个问题,但我相信我的情况不同,同样的规则可能不适用。每次我执行这个方法都会弹出同样的错误。位置0处没有行。如果我将[0]更改为[1]或[15];[1]等处没有行。这是否意味着我的数据库甚至没有连接?我是否应该编写某种if语句来确定检查行是否存在?publicboolUpdateOrderToShipped(stringorder){orderNumber=order;stringbatch=ConfigurationManager.AppSettings["SuccessfulOrderBatch"];stringstatement="UPDATESOP1010

c# - ASP.NET MVC 3 Razor : Passing Data from View to Controller

我对.NET的一切都是全新的。我有一个带有HTML表单的非常基本的网页。我希望“onsubmit”将表单数据从View发送到Controller。我看过与此类似的帖子,但都没有涉及新的Razor语法的答案。我如何处理“onsubmit”,以及如何从Controller访问数据?谢谢!! 最佳答案 您可以将要传递的View控件包装在Html.Beginform中。例如:@using(Html.BeginForm("ActionMethodName","ControllerName")){...yourinput,labels,text

c# - 无效操作异常 : No IAuthenticationSignInHandler is configured to handle sign in for the scheme: MyCookieAuthenticationScheme

我正在尝试按照说明进行操作here将Cookie身份验证添加到我的网站。到目前为止,我添加了以下内容:InvoketheUseAuthenticationmethodintheConfiguremethodoftheStartup.csfile:app.UseAuthentication();InvoketheAddAuthenticationandAddCookiemethodsintheConfigureServicesmethodoftheStartup.csfile:services.AddAuthentication("MyCookieAuthenticationScheme

c# - LINQ to Entities/LINQ to SQL : switching from server (queryable) to client (enumerable) in the middle of a query comprehension?

在许多情况下,我想在服务器端进行一些过滤(有时是投影),然后切换到客户端以执行LINQ提供程序本身不支持的操作。天真的方法(这基本上就是我现在所做的)是将其分解为多个查询,类似于:varfromServer=fromtincontext.Tablewheret.Col1=123wheret.Col2="blah"selectt;varclientSide=fromtinfromServer.AsEnumerable()wheret.Col3.Split('/').Last()=="whatever"selectt.Col4;但是,很多时候,这带来的代码/麻烦多于它的实际值(value)

c# - 跨线程操作无效(How to access WinForm elements from another module events?)

我有一个带有串行端口信号事件的模块serialPort.DataReceived.AddHandler(SerialDataReceivedEventHandler(DataReceived));DataReceived在哪里letDataReceivedab=rxstringProcessData正在调用WinForms方法letProcessData(a,b)=dataProcessor.Invoke(a,b)|>ignore这是privatevoidProcessData(objectsender,EventArgse){byte[]m=Core.ncon.ArrayRead;s

c# -/平台 :anycpu32bitpreferred is not a valid setting for option/target:library or/target:module

我创建了一个Windows服务项目,后来决定将其输出类型更改为类库,这样我就可以将服务类包含在另一个项目中,该项目将创建要作为服务安装的.exe。但是现在,当我尝试构建第一个项目时,它失败并出现错误:/platform:anycpu32bitpreferredisnotavalidsettingforoption/target:libraryor/target:module我该如何解决这个问题? 最佳答案 尝试卸载项目(在解决方案资源管理器中右键单击)编辑.csproj(右键单击解决方案资源管理器)删除true重新加载项目。

c# - 为什么这个程序会出错? `Object synchronization method was called from an unsynchronized block of code`

这段代码有什么问题?我收到“从未同步的代码块调用对象同步方法”。我在谷歌上发现了一个结果,说我可能在锁定之前释放了一个互斥体,但根据我的输出,情况并非如此。这是互斥锁代码,中间没有其他代码。-edit-对不起大家,贴错了。我的输出1W1W2W代码usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Threading;namespacesqliteTest{classProgram{staticvolatileMutexmut1=newMutex();staticvolatileMutexmut

c# - 为什么我会收到 "The modifier ' virtual'is not valid for this item“错误?

我正在尝试使用以下模型创建mvc应用程序:(代码很大。我认为它对您来说更容易理解)publicclassJob{publicintJobId{get;set;}publicstringName{get;set;}publicListGetJobs(){ListjobsList=newList();jobsList.Add(newJob{JobId=1,Name="Operator"});jobsList.Add(newJob{JobId=2,Name="Performer"});jobsList.Add(newJob{JobId=3,Name="Head"});returnjobsLi