Users Online

· Guests Online: 23

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Illustrate Actions

C# Program to Illustrate Actions

 

This is a C# Program to illustrate actions.

Problem Description

This C# Program Illustrates Actions.

Problem Solution

Here action objects return no values.

Program/Source Code

Here is source code of the C# Program to Illustrate Actions. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Illustrate Actions
 */
using System;
 
class Program
{
    static void Main()
    { 
        Action<int> action1 =(int x) => Console.WriteLine("OUTPUT {0}", x);
        Action<int, int> action2 =(x, y) => Console.WriteLine("OUTPUT {0} and {1}", 
                                                                x, y);
        action1.Invoke(1111);
        action2.Invoke(200, 3000);
        Console.Read();
    }
}
Program Explanation

This C# program is used to illustrate actions. We are creating two objects ‘action1’ and ‘action2’ using Action<int>. The Action<int> is used to encapsulate a method that has a single parameter and does not return a value. Here Action objects return no values. Pass the values of ‘action1’ and ‘action2’ variables as an argument to Invoke().

 
Runtime Test Cases
 
OUTPUT 1111
OUTPUT 200 and 3000

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.55 seconds
14,558,354 unique visits