basic:是否可以在方法声明中定义可选参数?怎么样? [英] basic: Is it possible to define optional parameters in a method declaration? how?

查看:82
本文介绍了basic:是否可以在方法声明中定义可选参数?怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谢谢,

Juan。

Thanks,
Juan.

推荐答案

是的。只需重载该方法。


公共类MyClass

{

public void MyMethod(int x,int y)

{

...

}


public void MyMethod(int x)

{

MyMethod(x,0);

}

}


现在你有一个有单一的课程方法,具有两个选项。如何
来称呼它。


希望有所帮助。


Patrick Altman

<><

Juan写道:
Yes. Just overload the method.

public class MyClass
{
public void MyMethod(int x, int y)
{
...
}

public void MyMethod(int x)
{
MyMethod(x, 0);
}
}

Now you have a class with a "single" method, with two "options" of how
to call it.

Hope that helps.

Patrick Altman
<><
Juan wrote:
谢谢,
Juan。
Thanks,
Juan.



-

-

Patrick Altman

<><



--
--
Patrick Altman
<><


不,C#没有给你能力有像C ++或

VB这样的可选参数。你可以做的最好的就是函数重载,因为Patrick指出

out。


-


Chris Rolon


此帖子按原样提供。没有保证,也没有赋予任何权利。


Patrick Altman < PA ********** @ gmail.com>在消息中写道

news:e9 ************** @ tk2msftngp13.phx.gbl ...
No, C# does not give you the ability have optional parameters like in C++ or
VB. The best that you could do is function overloading, as Patrick pointed
out.

--

Chris Rolon

This posting is provided "AS IS" with no warranties, and confers no rights.

"Patrick Altman" <pa**********@gmail.com> wrote in message
news:e9**************@tk2msftngp13.phx.gbl...
是的。只是重载方法。

public class MyClass
{public void MyMethod(int x,int y)

...
>}

public void MyMethod(int x)
{
MyMethod(x,0);
}
}
现在你有一个带有单一的课程。方法,具有两个选项。如何调用它。

希望有所帮助。

Patrick Altman
<><

Juan写道:
Yes. Just overload the method.

public class MyClass
{
public void MyMethod(int x, int y)
{
...
}

public void MyMethod(int x)
{
MyMethod(x, 0);
}
}

Now you have a class with a "single" method, with two "options" of how
to call it.

Hope that helps.

Patrick Altman
<><
Juan wrote:
谢谢,
Juan。
Thanks,
Juan.



-
-
Patrick Altman
<><



--
--
Patrick Altman
<><



我明白了。感谢洛杉矶,我会超载。


" Chris Rolon" < CR **** @ hotmail.com> escribióenel mensaje

新闻:eM ************** @ TK2MSFTNGP12.phx.gbl ...
I see. Thanks a los, i will overload then.

"Chris Rolon" <cr****@hotmail.com> escribió en el mensaje
news:eM**************@TK2MSFTNGP12.phx.gbl...
不,C#做没有给你能力有可选参数,如在C ++
或VB中。你可以做的最好的是功能超载,正如帕特里克指出的那样。

-

克里斯罗恩

这个帖子是提供按原样没有保证,也没有授予
权利。
Patrick Altman < PA ********** @ gmail.com>在消息中写道
新闻:e9 ************** @ tk2msftngp13.phx.gbl ...
No, C# does not give you the ability have optional parameters like in C++ or VB. The best that you could do is function overloading, as Patrick pointed
out.

--

Chris Rolon

This posting is provided "AS IS" with no warranties, and confers no rights.
"Patrick Altman" <pa**********@gmail.com> wrote in message
news:e9**************@tk2msftngp13.phx.gbl...
是的。只是重载方法。

public class MyClass
{public void MyMethod(int x,int y)

...
>}

public void MyMethod(int x)
{
MyMethod(x,0);
}
}
现在你有一个带有单一的课程。方法,具有两个选项。如何调用它。

希望有所帮助。

Patrick Altman
<><

Juan写道:
Yes. Just overload the method.

public class MyClass
{
public void MyMethod(int x, int y)
{
...
}

public void MyMethod(int x)
{
MyMethod(x, 0);
}
}

Now you have a class with a "single" method, with two "options" of how
to call it.

Hope that helps.

Patrick Altman
<><
Juan wrote:
谢谢,
Juan。
Thanks,
Juan.



-
-
Patrick Altman
<><



--
--
Patrick Altman
<><




这篇关于basic:是否可以在方法声明中定义可选参数?怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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