Q:

Explain Cascaded Method call in C# with an Example

0

Explain Cascaded Method call in C# with an Example

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Demo
    {
	
		public Demo FUN1()
		{
            		Console.WriteLine("\nFUN1 CALLED");

			return this;
		}

        public Demo FUN2()
        {
            Console.WriteLine("\nFUN2 CALLED");

            return this;
        }

        public Demo FUN3()
        {
            Console.WriteLine("\nFUN3 CALLED");

            return this;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            Demo D;

            D = new Demo();

            D.FUN1().FUN2().FUN3();

        }
    }
}

Output

FUN1 CALLED
FUN2 CALLED
FUN3 CALLED

In this program, class "Demo" contains three methods and each method is returning "this", which contains the reference of object. And by using the reference of object we can call multiple functions in a statement.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program for Default Arguments... >>
<< \'this\' reference in C#.Net with Exampl...