Friday, April 30, 2021

C# return statement in a Method



using System;

namespace Console_Function_return_keyword
{
    class Program
    {
        public void MyMethod()
        {
            Console.WriteLine("Hi");
            return;
        }
        public string NextMethod()
        {
            return "Hello";
        }
        public string AnotherMethod()
        {
            return "Hello";
            Console.WriteLine("I am unreachable code");
        }
        static void Main(string[] args)
        {
            Program p = new Program();
            p.MyMethod();
            Console.WriteLine(p.NextMethod()); 
        }
    }
}
OUTPUT
Hi
Hello

No comments:

Post a Comment

Hot Topics