gpt4 book ai didi

c# - 有没有一种情况我们需要一个扩展方法,其默认值是被扩展的对象?

转载 作者:行者123 更新时间:2023-11-30 21:03:23 25 4
gpt4 key购买 nike

是否存在这样一种情况,我们需要一个扩展方法,其默认值是被扩展的对象?

例如,

public static class util
{
public static string Foo(this string name="Hello world")
{
return name;
}
}

最佳答案

我不确定是否会出现这种情况,但你不能那样做。你会得到一个错误:

Cannot specify a default value for the 'this' parameter

关于c# - 有没有一种情况我们需要一个扩展方法,其默认值是被扩展的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12929260/

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