Event Demo with Anonimous method & Lambdas expresions

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

namespace EventDemo {
class Program {
static void Main(string[] args) {
Car car = new Car();
// 1 Ordinare Expresion
//car.SpeedLimitExceeded += new SpeedLimitExceededEventHandler(CarSpeedLimitExceeded);

// 2 Delegate wiht Anonimous method
//car.SpeedLimitExceeded += delegate(object source, SpeedEventArgs e) {
// Console.WriteLine(“Speed limit exceeded by {0}mph”, e.ExcessSpeed);

// 3 Lambdas expresions
car.SpeedLimitExceeded += (object source, SpeedEventArgs e) => {
Console.WriteLine(“Speed limit exceeded by {0}mph”, e.ExcessSpeed);

for(int i = 0; i < 3; i++) {
Console.WriteLine(“Speed: {0}mph”, car.Speed);



—–> Download <——

Using lambdas - C++ vs. C# vs. C++/CX vs. C++/CLI

* This source code was highlighted with Source Code Highlighter.

This entry was posted in C# Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s