有什么办法可以在C#
中编写独立功能?我需要一个函数,但我不认为它是任何现有class
的成员,并且我看不到任何写作重点
public abstract class HolderForFunctionsThatIDontKnowWhereElseToPut
{
MyReturnType MyFuction ( ... ) { ... }
}
最佳答案
不。没有类/结构,就无法拥有一个功能。
您只能在类或结构内使用函数(方法)。
参见:Why Doesn't C# Implement "Top Level" Methods? (Eric Lippert)
关于c# - 如果我想要一个独立的功能怎么办?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33903662/