Skip to content

Instantly share code, notes, and snippets.

@ezirmusitua
Created September 10, 2019 21:46
Show Gist options
  • Save ezirmusitua/3a89cd740a6fd5d74410442699d815fb to your computer and use it in GitHub Desktop.
Save ezirmusitua/3a89cd740a6fd5d74410442699d815fb to your computer and use it in GitHub Desktop.
[Use Action as parameter with unlimited parameters] #C#
// 不加参数的 Action 参数可以传拥有任意数目参数的函数
protected void udpCommand(Action command)
{
while(!linkDownFail)
{
try
{
command();
break;
}
catch
{
LinkStateCallBack(ip, getLinkStatus());
if (linkDownFail) throw new LinkDownException();
Thread.Sleep(100);
}
}
return;
}
udpCommand(() => noParameterMethod());
udpCommand(() => singleParameterMethod(value));
udpCommand(() => manyParameterMethod(value, value2, value3, value4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment