"预期类,委托,枚举,接口或结构"公共静态字符串MYFUNC错误()。什么是替代"串QUOT ;? [英] "Expected class, delegate, enum, interface or struct" error on public static string MyFunc(). What's an alternative to "string"?
问题描述
我得到一个错误,当我尝试使用下面的静态函数
I'm getting an error when I attempt to use the following static function.
错误:
预期类,委托,枚举,接口或结构
Expected class, delegate, enum, interface, or struct
函数(类):
namespace MyNamespace
{
public class MyClass
{
// Some other static methods that use Classes, delegates, enums, interfaces, or structs
public static string MyFunc(string myVar){
string myText = myVar;
//Do some stuff with myText and myVar
return myText;
}
}
}
这导致编译器一气之下(红色)强调公共静态字符串
的字符串的一部分。
This is causing the compiler to angrily (in red) underline the string part of public static string
.
所以,我认为这个办法字符串
是不是一类,委托,枚举,接口或结构。
So, I assume this means string
is not a class, delegate, enum, interface, or struct.
我可以使用字符串
,而不是返回一个字符串或字符串状物体?似乎没有要在C#中的字符串
(大写S)类。
What can I use instead of string
to return a string or string-like object? There doesn't appear to be a String
(capital S) class in C#.
修改:支架不匹配的一些注释代码 - 上面的代码工作正常,我的实际不匹配的代码没有。谢谢!
Edit: Bracket mis-match with some commented code - the above code works correctly, my actual mis-matched code didn't. Thanks!
推荐答案
您需要把方法定义成一个类/结构的定义。方法定义不能出现之外的。
You need to put the method definition into a class/struct definition. Method definitions can't appear outside those.
这篇关于"预期类,委托,枚举,接口或结构"公共静态字符串MYFUNC错误()。什么是替代"串QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!