A main function in C# can only return either
int
, or
void
type, nothing else. You cannot force it to return anything other than that, because of the legacy stuff—try reading why C or C++ programs start with
int main() { }
.
That said, in your code, you are not even trying to return anything. Instead, you are
capturing input. Console.ReadLine() is used to capture the input and then process, such as the one you are doing—
if(s = "string")
. Now, to return something you need to change the return type of the function and you need to use the
return
keyword to return a value. You are not doing that anywhere. Any other function that returns a string would be like this,
public static string Greetings() {
Console.WriteLine("Enter your name: ");
string name = Console.ReadLine();
return "Hello, " + name + "!";
}
So, I would recommend going through C# documentation a bit more so that you can understand how this works. :-)
Main() Return Values (C# Programming Guide) | Microsoft Docs[
^]