Can I somehow make a prototype of method and declare its body in C# like I do in C++?
For example in C++:
void foo();
int main()
{
foo();
return 0;
}
void foo(){
cout << "im foo";
}
How can I achieve it in C#?
There are partial methods in C#, which I think is quite similar.
Partial methods must be private
and return void
. If your methods are not private or do not return void
, consider using the second approach below.
Here's an example of a partial method:
partial class MyClass {
partial void Foo();
}
// This can be in another file
partial class MyClass {
partial void Foo() {
Console.WriteLine("Foo");
}
}
Another approach is to use interfaces:
interface IFoo {
void Foo();
}
class MyClass: IFoo {
public void Foo() {
Console.WriteLine("Foo");
}
}
However, if you just want to see all the methods in a class in a neat way, Visual Studio can already do that for you. I don't have Visual Studio on the computer that I'm currently using so here's a screenshot I found on Google:
The part where it says "RunFile(PythonEngine engine...)" is where you want to click. After you clicked All the methods in the current file will be displayed. You can click on one of them to jump to it!