草庐IT

ref-parameters

全部标签

c# - "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions"错误

为什么我收到错误:Templatescanbeusedonlywithfieldaccess,propertyaccess,single-dimensionarrayindex,orsingle-parametercustomindexerexpressions在此代码处:@modelIEnumerable@{ViewBag.Title="Index";Layout="~/Views/Shared/_PageLayout.cshtml";}Index@Html.ActionLink("CreateNew","Create")@foreach(variteminModel){@Html.

c# - 引用分配是原子的,那么为什么需要 Interlocked.Exchange(ref Object, Object) 呢?

在我的多线程asmxWeb服务中,我有一个我自己的类型SystemData的类字段_allData,它由几个List组成和Dictionary标记为volatile.系统数据(_allData)偶尔会刷新一次,我通过创建另一个名为newData的对象来实现。并用新数据填充它的数据结构。完成后,我只需分配privatestaticvolatileSystemData_allDatapublicstaticboolLoadAllSystemData(){SystemDatanewData=newSystemData();/*fillnewDatawithup-to-datedata*/..

C# 4.0 : Can I use a TimeSpan as an optional parameter with a default value?

这两个都会产生一个错误,指出它们必须是编译时常量:voidFoo(TimeSpanspan=TimeSpan.FromSeconds(2.0))voidFoo(TimeSpanspan=newTimeSpan(2000))首先,有人能解释一下为什么这些值不能在编译时确定吗?有没有办法为可选的TimeSpan对象指定默认值? 最佳答案 您可以通过更改签名轻松解决此问题。voidFoo(TimeSpan?span=null){if(span==null){span=TimeSpan.FromSeconds(2);}...}我应该详细说明

c# - C# 中的引用类型变量 "ref"有什么用?

我知道如果我传递一个值类型(int、struct等)作为参数(没有ref关键字),该变量的副本被传递给该方法,但如果我使用ref关键字,传递的是对该变量的引用,而不是新的引用。但是对于引用类型,比如类,即使没有ref关键字,引用也会传递给方法,而不是副本。那么ref关键字和引用类型有什么用呢?举个例子:varx=newFoo();以下有什么区别?voidBar(Fooy){y.Name="2";}和voidBar(refFooy){y.Name="2";} 最佳答案 您可以使用y更改foo指向的内容:Foofoo=newFoo("1

c# - 不一致的可访问性 : Parameter type is less accessible than method

我试图在两种形式之间传递一个对象(基本上是对当前登录用户的引用)。目前,我在登录表单中有以下内容:privateACTInterfaceoActInterface;publicvoidbutton1_Click(objectsender,EventArgse){oActInterface=newACTInterface(@"\\actserver\Database\Premier.pad",this.textUser.Text,this.textPass.Text);if(oActInterface.checkLoggedIn()){//userhasauthedagainstACT,

c# - 何时使用 in vs ref vs out

前几天有人问我什么时候应该使用参数关键字out而不是ref。虽然我(我认为)理解ref和out关键字(一直是askedbefore)之间的区别,但最好的解释似乎是ref==in和out,我应该始终使用out而不是的一些(假设或代码)示例引用。既然ref更通用,为什么还要使用out?它只是语法糖吗? 最佳答案 除非你需要ref,否则你应该使用out。当数据需要编码时,它会产生很大的不同,例如到另一个过程,这可能是昂贵的。因此,您希望避免在方法未使用初始值时编码初始值。除此之外,它还向声明或调用的读者显示初始值是相关的(并可能保留)还是

c# - .NET 中 ref 和 out 参数的区别

这个问题在这里已经有了答案:What'sthedifferencebetweenthe'ref'and'out'keywords?(27个答案)关闭4年前。.NET中的ref和out参数有什么区别?在什么情况下一个比另一个更有用?一个可以使用而另一个不能使用的代码片段是什么?

javascript - Firebase - ref 和 child 有什么区别?

在Firebase中,ref和child被大量使用。例如-firebase.database().ref('users/')将与firebase.database().ref('users').child('')完全相同,那么它们之间到底有什么区别,什么时候应该使用它们? 最佳答案 没有区别,无论如何你有一个DatabaseReference实例。Firebase引用代表数据库中的特定位置,可用于读取数据或将数据写入该数据库位置。方法:publicDatabaseReferencegetReference(Stringpath)获取

javascript - "Stateless function components cannot be given refs"是什么意思?

我有这个:constProjectsSummaryLayout=({projects})=>{return(Projects{projects.map(p=>{p.contract.client})})}constProjectsSummary=connect(state=>({projects:state.projects}))(ProjectsSummaryLayout)我得到:Warning:Statelessfunctioncomponentscannotbegivenrefs(Seeref"wrappedInstance"inProjectsSummaryLayoutcrea

javascript - 错误 : Failed to execute 'appendChild' on 'Node' : parameter 1 is not of type 'Node'

我正在尝试将图像拖放到div上。图像没有被拖到div上并给出以下错误UncaughtTypeError:Failedtoexecute'appendChild'on'Node':parameter1isnotoftype'Node'.draganddrop.html:20dropdraganddrop.html:26ondrop代码CreativityDashboardfunctionallowDrop(ev){ev.preventDefault();}functiondrag(ev){ev.dataTransfer.setData("text",ev.target.id);}func