1.

If A Method's Return Type Is Void, Can You Use A Return Keyword In The Method?

Answer»

Yes, Even though a method's return type is void, you can use the return keyword to stop the execution of the method as shown in the example below.

using SYSTEM;
namespace DEMO
{
class Program
{
public static void MAIN()
{
SayHi();
}
public static void SayHi()
{
Console.WriteLine("Hi");
return;
Console.WriteLine("This statement will NEVER be executed");
}
}
}

Yes, Even though a method's return type is void, you can use the return keyword to stop the execution of the method as shown in the example below.

using System;
namespace Demo
{
class Program
{
public static void Main()
{
SayHi();
}
public static void SayHi()
{
Console.WriteLine("Hi");
return;
Console.WriteLine("This statement will never be executed");
}
}
}



Discussion

No Comment Found