gpt4 book ai didi

c# - 是否可以为控制台编写扩展方法?

转载 作者:IT王子 更新时间:2023-10-29 04:21:21 24 4
gpt4 key购买 nike

<分区>

同时查看 this question我认为为 System.Console 编写包含所需功能的扩展方法是个好主意。

然而,当我尝试它时,我得到了这个编译错误

System.Console': static types cannot be used as parameters

代码如下:

using System;
using System.Runtime.CompilerServices;

namespace ConsoleApplication1
{
public static class ConsoleExtensions
{
[Extension]
public static string TestMethod(this Console console, string testValue)
{
return testValue;
}

}
}

还有另一种为静态类型创建扩展方法的方法吗?或者这是不可能的?

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