什么“(test1,test2,test3 =”3“,test4 =”4“,test5 =”5“,test6 =”6“)”做什么?(What does “(test1, test2, test3=”3“, test4=”4“, test5 = ”5“, test6 = ”6“)” do?)
这个问题是基于我最近在同事工作中找到的一些非常奇怪的代码。 他声称不知道它是如何工作的,只是他从其他地方复制了它。 这对我来说不够好,我想了解这里发生了什么。
如果我们有类似的东西:
(test1, test2, test3="3", test4="4")
结果将是
test1 == "3"
,test2 == "4"
,test3 == nil
和test4 == "4"
。 我明白为什么会发生这种情况,但如果我们这样做:(test1, test2, test3="3", test4="4", test5 = "5", test6 = "6")
现在结果是
test1 == "3"
,test2 == "4"
,test3 == "5"
,test4 == "4"
,test5 == "5"
,test6 == "6"
。为什么
test5 == nil
?This question is based off some really odd code I recently found in a colleagues work. He claims not to know how it works only he copied it from somewhere else. That's not good enough for me, I want to understand what's going on here.
If we have something like:
(test1, test2, test3="3", test4="4")
The result will be that
test1 == "3"
,test2 == "4"
,test3 == nil
andtest4 == "4"
. I understand why this happens, but if we do something like:(test1, test2, test3="3", test4="4", test5 = "5", test6 = "6")
now the result is
test1 == "3"
,test2 == "4"
,test3 == "5"
,test4 == "4"
,test5 == "5"
,test6 == "6"
.Why isn't
test5 == nil
?
原文:https://stackoverflow.com/questions/3065488
最满意答案
委托定义了实施者必须使用的签名。 在您的情况下,您定义了一个方法,该方法将字符串作为输入参数并且什么都不返回。 为了使用它,您的实现方法必须与该签名一致。 例如,如果您希望它的行为类似于GreetingDelegate,则问候方法(顺便说一句,正确拼写您的方法)将需要如下所示:
Public Sub Greeting(msgString As String) ' Do something with msgString End Sub
或者,如果您不需要输入字符串,您的委托可以声明如下,但是要意识到您定义此委托类型的所有方法也不允许输入字符串参数(因为它们不同意声明的签名)。
Public Delegate Sub GreetingDelegate()
A delegate defines the signature that implementers must use. In your case, you defined a method that takes a string as input parameter and returned nothing. In order to use that, your implementing methods must agree with that signature. For example, a greeting method (BTW, spell your methods correctly), would need to be as follows if you want it to behave like a GreetingDelegate:
Public Sub Greeting(msgString As String) ' Do something with msgString End Sub
Alternatively, if you don't need the input string, your delegate could be declared as follows, but realize that all methods that you are defining of this delegate type would also not allow input string parameters either (because they wouldn't agree with the declared signatures).
Public Delegate Sub GreetingDelegate()
相关问答
更多-
VB.NET和vb的区别大吗[2022-08-11]
java的特色,网上多得是!这里主要补充一些实际的例子! 1,用java开发业务教复杂的程序,相对来说要轻松一些!因为java社区丰富!本身灵活度很高,并且是OO的语言!可以套现设计模式! 2,java的多数框架都是开源的!学习java很方便!成本低!(.net不开放源码) 3,.net是一个框架,与java语言不相关!具体可以与一些开源框架比较,例如spring,webwork,hibernate等等. 4,java的执行效率没有.net高! 综述,.net适合做网站,中型的!java适合做后台,企业系统 ... -
vb.net那里下载[2022-12-02]
官方下载地址:http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express 此为:vb.net express版本,没有时间限制 -
vb.net 教程[2023-07-19]
http://msdn.microsoft.com/zh-cn/library/2x7h1hfk.aspx 微软官方MSDN是最权威的初学场所 -
如果类型是引用类型(即:类),则它是引用副本。 如果它是一个值类型(结构),它将通过成员复制来完成一个成员。 It's a reference copy, if the type is a reference type (ie: classes). If it's a value type (Structure), it will do a member by member copy.
-
vb.net复杂if语句(vb.net complex if statement)[2023-09-07]
这看起来不错吗? 格式化应该可以帮到你。 当您单击If语句的其中一个元素时,将突出显示所有部分以显示它们所属的位置。 If form3.TextBox1.Text = "" Then Dim result1 As DialogResult = MessageBox.Show("Click OK to fill out user settings, or CANCEL to do it later", "Settings", MessageBoxButtons.OKCancel) If res ... -
VB不区分大小写,因此它实际上分配给parentWindow和documentCount 。 (编辑回应其他评论) VB is case insensitive, so it's actually assigning to parentWindow and documentCount. (Edited in response to other comment)
-
委托定义了实施者必须使用的签名。 在您的情况下,您定义了一个方法,该方法将字符串作为输入参数并且什么都不返回。 为了使用它,您的实现方法必须与该签名一致。 例如,如果您希望它的行为类似于GreetingDelegate,则问候方法(顺便说一句,正确拼写您的方法)将需要如下所示: Public Sub Greeting(msgString As String) ' Do something with msgString End Sub 或者,如果您不需要输入字符串,您的委托可以声明如下,但是要意识到您 ...
-
感谢您提出这些观点。 请注意,并非每次都适用所有规则。 有些情况下,我们需要在误报/漏报/真实案例之间取得平衡。 例如,在运算符规则的两侧使用相同的表达式。 拥有相同的操作数是一个错误吗? 不,这不对。 如果是,则编译器将报告它。 这是难闻的气味,通常是一个错误吗? 在许多情况下是的。 例如在Roslyn中看到这个。 我们应该调整此规则以排除某些情况吗? 是的,我们应该, 2 << 2没有错。 因此需要进行大量的平衡,并且我们试图解决为用户带来最大价值的实现。 对于你提出的观点: 同一条件结构中的两个分支不 ...
-
从QBasic到VB.Net的ATN(ATN from QBasic to VB.Net)[2024-02-23]
我怀疑你遇到了QBasic的老式16位限制。 当恐龙走向地球时,人们在QBasic中使用单精度浮点数学,他们知道该变量只能存储7个有效数字。 因此,如果您的QBasic数据类型是单打,那么无论您认为自己输入什么,在QBasic中它们实际上都是: PI = 3.141592 X(Z, 2) = 6.892910 X(Z, 1) = -5.088647 I just leanrned that there is no problem in my calculation. The reason why the ... -
插入OLEDB VB.NET(Insert into OLEDB VB.NET)[2022-01-22]
关于DataAdapter.Update的作用,你有点困惑。 Update可以将InsertCommand,UpdateCommand,DeleteCommand应用于DataSource中存在的每个已添加,已修改或已删除的行(假设ds是一个DataSet)。 它不会自己添加/删除/更新记录到数据库。 如果要将记录添加到数据库,则应编写(伪)代码 Using con = GetConnection() Using cmd = new con.CreateCommand() cmd.CommandTe ...