Shazma Batool

Shazma Batool

  • NA
  • 101
  • 5.4k

Output a string on console with return statement C#

May 14 2022 8:47 AM

How to show the output "This is a print name method" from a return statement. This is the code below thanks

class Print{

static string PrintName()

{

string output="This is a print name method";

Console.WriteLine(output);

return output; 

}

static void Main()

{

Print.PrintName();

}

}

PS. When I set my Main() method's return type to string it gives me error that include static Main() method for an entry point.. Does this mean that Main() method can be only of a void return type as a standard return type just like the Main() method itself which has been declared as a standard method serving as an entry point for our programs to be executed and cannot directly execute our own defined methods in this case PrintName() method.

Thanks a bunch!

 

 

 


Answers (3)