“Expected class, delegate, enum, interface or struct” error on public static string MyFunc(). What's an alternative to “string”?

前端 未结 3 1284
忘了有多久
忘了有多久 2021-01-04 10:23

I\'m getting an error when I attempt to use the following static function.

Error:

Expected class, delegate, enum, interface, or struct

3条回答
  •  天命终不由人
    2021-01-04 10:45

    There is a capital S String in C#/.Net - System.String. But that is not your problem. @Femaref got it right - this error is indicating that your method is not part of a class.

    C# does not support standalone functions, like C++ does. All methods have to be declared within the body of a class, interface or struct definition.

提交回复
热议问题