gpt4 book ai didi

c# - 我可以在 C# 中使用默认参数吗?

转载 作者:太空宇宙 更新时间:2023-11-03 17:22:20 29 4
gpt4 key购买 nike

我有以下功能:

public ActionResult Index(string caller_id, int? id)
{

现在我使用下面的代码来设置一个值:

var _id = id.HasValue ? (int) id : 0;

在没有设置 id 的情况下调用函数时,我可以将 id 的值设为默认值吗?

谢谢,

艾莉森

最佳答案

是的,您可以这样做,但前提是您使用 .net 4.0+

public ActionResult Index(string caller_id, int id = 0)

Named and Optional Arguments (@msdn)

关于c# - 我可以在 C# 中使用默认参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5644238/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com