将void作为参数传递给静态方法 [英] Pass void as a parameter to a static method

查看:67
本文介绍了将void作为参数传递给静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,该列表从另一个下拉列表填充.此操作发生在我网站的许多网页上.我考虑过创建一个通用方法,该方法需要一些参数,这些参数将填充从属下拉列表.以下是我建议的静态方法:

I have one dropdown list that is filled from another dropdown list. This action takes place in many web pages of my site. I thought about creating a general method that takes some parameters which will fill the dependant dropdown list. The following is my proposed static method:

public static  void FillDropDownList(string Parent_Ddl_Value,
                                     DropDownList Child_Ddl,
                                     ?? voidtofillchilddropdownlist);




我需要将此void voidtofillchilddropdownlist传递为参数&执行吗?如何做到这一点.




I need to pass this void voidtofillchilddropdownlistas parameters & execute it? How can this be achieved.

Thanks for your time!

推荐答案

您不能传递空缺-空缺就是缺少某些东西.
要么传递一个空值,要么(我怀疑)传递一个delegate.后者是可以在FillDropDownList中执行以进行实际填充的方法的指针":MSDN可以最好地解释如何做到这一点. http://msdn.microsoft.com/en-us/library/ms173172.aspx [ ^ ]
You cannot pass a void - a void is the absence of something.
Either pass a null, or (as I suspect) pass a delegate. The later is a "pointer to a method" that can be executed in FillDropDownList to do the actual filling: MSDN can explain best how to do that. http://msdn.microsoft.com/en-us/library/ms173172.aspx[^]


我不确定此处的方法是否正确,但您的要求不清楚. (此外,我猜测DropDownList实际上是一个winfows.forms.comboBox,但由于我不能保证我不会对所公开的方法/属性做任何假设)

你:
I''m not sure your approach is correct here but your requirements are unclear. (Also, im guessing DropDownList is actually a winfows.forms.comboBox but since i cant gurantee that im going to make no assumptions about the exposed methods/properties)

do you:

  1. 是否要将一个下拉列表的全部内容复制到另一个列表?
    您应该具有以下参数:

    • DropDownList sourceList
    • dropDownList destinationList

  1. Want to copy the entire contents of one drop-down list to another?
    you should have the following arguments:

    • DropDownList sourceList
    • dropDownList destinationList

  • object valueToCopy
  • dropDownList destinationList

  • DropDownList sourceList
  • dropDownList destinationList
  • int firstValueIndex
  • int lastValueindex

  • DropDownList sourceList
  • dropDownList destinationList
  • int firstValueIndex
  • int lastValueindex

  • DropDownList sourceList
  • dropDownList destinationList
  • int [] indexToTo



希望对您有所帮助!



I hope that helps you some!


OriginalGriff [ ^ ]您所追求的最有可能是代表.除了该方法不应返回任何内容外,您仍然错过了告诉我们该委托人的签名的信息.我认为,仅出于副作用的目的调用此方法.

请详细说明您的问题,并通过调用此方法(通过委托传递)来告诉我们您要实现的目标,我将根据您提供的附加信息来更新我的解决方案.使用链接 改善问题 改善您的问题.

最好的问候,

—MRB
As OriginalGriff[^] already mentioned it''s most likely that it is delegates that you''re after. You still missed telling us what the signature of that delegate is though, apart from the fact that the method is not supposed to return anything. I take it then, that this method is called solely on the purpose of it''s side effect.

Please elaborate on your question and tell us what you''re trying to achieve by calling this method which is passed in via a delegate and I will update my solution in accordance to the added information you''ll supply. Use the link Improve question to improve your question.

Best Regards,

—MRB


这篇关于将void作为参数传递给静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆