gpt4 book ai didi

c# - 在 C# 的控制台程序中使用 [STAThread]

转载 作者:太空狗 更新时间:2023-10-30 00:19:43 25 4
gpt4 key购买 nike

我已经为 C# 控制台应用程序编写了代码。它将剪贴板中的值复制到文件中,并且运行时没有任何错误。

现在我想在另一个带有其他代码的 C# 项目中使用它。

我在 class{} 之后使用 [STAThread],但它给我一个错误:

:: Attribute 'STAThread' is not valid on this declaration type. It is only valid on 'method' declarations.

我能做什么?

最佳答案

您只能将 [STAThread] 放在入口点方法(不是类)之上,并且只能在库中放置一次。您要将此代码复制到的项目类型是什么?它甚至需要 STA 属性吗?方法是静态的吗?

错误是说你将 [STAThread] 放在方法之外的其他东西上。

发布你的代码。

关于c# - 在 C# 的控制台程序中使用 [STAThread],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17339818/

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