English 中文(简体)
是否有VB。 相当于C#外参数的网络?
原标题:Is there a VB.NET equivalent of C# out parameters?

页: 1 NET具有类似于C#out功能参数的直接等值,在这些参数中,转换成功能不必先入选?

最佳回答

outVB中的关键词。

然而,VB确实自动以某种方法对所有当地变量进行初步计算,因此,你可以使用<代码>。 通过Ref,无需首先明确列出变量。

例:

Sub Main()
  Dim y As Integer
  Test(y)
End Sub

Sub Test(ByRef x As Integer)
  x = 42
End Sub

(如果你在框架中审查代码(例如Double.TryParse),请见<OutAttribute>在参数上添加,但只有在发出呼吁时,方可对COMInterop或平台援引。)

问题回答

No, there is no equal structure that provide a non- originalised/2007/5 to be adopted to a methods without a press, but, as referred in my question https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.outattribute.aspx” rel=“noreferer”><Out()>vide on acode>ByRef para amount definition,尽管VB忽略了该定义,但s<_s/em>在C#中作为<>条码><><>>>>>>。

因此,我将先将参考变量引入Nothingand,具体说明<Out()>通过Ref来表示这一意向(如果C#user能使用你的方法的话)。

如果你知道你打算何时进入默认的<代码>Nothing,则你可在其他未签名的参考资料变量中确定“华沙配置”在分配之前的变量的利用”(>None>,在项目一级(项目和项目; Compile,并且你可能希望在改变这一环境之前对“所有组合”进行配置”,或者在VS2015(VB.NET 14)中,你可以使用<#code>B42030<>。

C# version

  void TestFunc(int x, ref int y, out int z) {
  x++;  
  y++;
  z = 5;
}

Vb.net版本

    Sub TestFunc(ByVal x As Integer, ByRef y As Integer, ByRef z As Integer)
  x += 1
  y += 1 
  z = 5 
End Sub

<>Update>

如评论所述,不要忘记初步分析你在排出位置中使用的参数。

我在VB有问题。 NET,我称之为一种“通过反射”功能,该功能又压倒了阵列。

尽管汇编者将它列为警告,但还是罚款。 设置是简单而可能是好的方案拟订做法。

Dim m_arr_values() as Integer

fnRetArray(m_arr_values)

纽约总部

  Even though  Nothing  is the default value, setting it
  s纽约总部ps the compiler complaining.
Dim m_arr_values() as Integer = Nothing

fnRetArray(m_arr_values)

如果可变姓名被描述,它也有助于编码。

Sub fnCreatePalette(ByRef arr_in_pal() As color, ByRef arr_out_pal() as uinteger)
    ...
End Sub

您可在VB采用参考方法。 NET。

你们需要C#中的参数机制,因为该机制不允许你使用任何变数,而不先入。

VB.NET并不需要一个特别关键词,因为它本身是自动的。

Just use byRef.





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?