×

VB.Net Programs

VB.Net program to implement the cascaded method call

By Nidhi Last Updated : November 15, 2024

Cascaded method call in VB.Net

Here, we will implement a cascaded method call using the 'Me' object. Each meth the current object using the Me object.

Program/Source Code:

The source code to implement the cascaded method call is given below. The given program is compiled and executed successfully.

VB.Net code to implement the cascaded method call

'VB.net program to implement the cascaded method call.

Module Module1
    Class Sample
        Function Fun1() As Sample
            Console.WriteLine("Fun1() called")
            Fun1 = Me
        End Function

        Function Fun2() As Sample
            Console.WriteLine("Fun2() called")
            Fun2 = Me
        End Function

        Function Fun3() As Sample
            Console.WriteLine("Fun3() called")
            Fun3 = Me
        End Function
    End Class

    Sub Main()
        Dim obj As New Sample()

        obj.Fun1().Fun2().Fun3()
    End Sub
End Module

Output

Fun1() called
Fun2() called
Fun3() called
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains a Sample class. In the Sample class, we created the three methods fun1(), fun2(), and fun3(). Each class returns the current object using the "Me" object to implement cascaded method calling.

At last, we created the Main() method, the Main() method is the entry point for the program. Here, we created the object of the Sample class and then called all methods in a single statement.

VB.Net User-defined Functions Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.