首页 \ 问答 \ 什么“(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“,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 == niltest4 == "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 and test4 == "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
更新时间:2022-05-24 11:05

最满意答案

委托定义了实施者必须使用的签名。 在您的情况下,您定义了一个方法,该方法将字符串作为输入参数并且什么都不返回。 为了使用它,您的实现方法必须与该签名一致。 例如,如果您希望它的行为类似于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()

相关问答

更多
  • 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.
  • 这看起来不错吗? 格式化应该可以帮到你。 当您单击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的老式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 ...
  • 关于DataAdapter.Update的作用,你有点困惑。 Update可以将InsertCommand,UpdateCommand,DeleteCommand应用于DataSource中存在的每个已添加,已修改或已删除的行(假设ds是一个DataSet)。 它不会自己添加/删除/更新记录到数据库。 如果要将记录添加到数据库,则应编写(伪)代码 Using con = GetConnection() Using cmd = new con.CreateCommand() cmd.CommandTe ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)