Click here to Skip to main content
15,891,423 members
Articles / Programming Languages / Visual Basic 10

A Look under the hood of the .NET Framework

Rate me:
Please Sign up or sign in to vote.
4.95/5 (78 votes)
11 Feb 2013CPOL49 min read 187.4K   1.5K   166  
Journey to the center of the .NET Framework with a chance of IL along the way!
using System;
using System.Windows.Forms;
using System.Collections.Generic;

namespace UnderTheHoodCSharp.Examples.LambdaExamples
{
	public class InsaneLambdaFactoryRewritten : IButtonFactory
	{
		private int _outerCounter = 1;
		IEnumerable<System.Windows.Forms.Button> IButtonFactory.GenerateButtons()
		{
			InnerClass1 lambda1 = new InnerClass1();
			lambda1.field_this = this;
			List<Button> list = new List<Button>();
			lambda1.counter = 1;
			for (int i = 1; i <= 10; i++)
			{
				InnerClass2 lambda2 = new InnerClass2();
				lambda2.locals = lambda1;
				lambda2.btn = new Button();
				lambda2.btn.Text = _outerCounter.ToString() + " - " + lambda1.counter.ToString();
				lambda2.btn.Click += lambda2.EventHandler;
				list.Add(lambda2.btn);
			}
			return list;
		}

		class InnerClass1
		{
			public int counter;
			public InsaneLambdaFactoryRewritten field_this;
		}

		class InnerClass2
		{
			public InnerClass1 locals;
			public Button btn;

			public void EventHandler(Object sender, EventArgs e)
			{
				locals.counter++;
				if (locals.counter % 10 == 0)
				{
					locals.field_this._outerCounter++;
				}
				btn.Text = locals.field_this._outerCounter.ToString() + " - " + locals.counter.ToString();
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO JUUN Software
Netherlands Netherlands
Sander Rossel is a Microsoft certified professional developer with experience and expertise in .NET and .NET Core (C#, ASP.NET, and Entity Framework), SQL Server, Azure, Azure DevOps, JavaScript, MongoDB, and other technologies.

He is the owner of JUUN Software, a company specializing in custom software. JUUN Software uses modern, but proven technologies, such as .NET Core, Azure and Azure DevOps.

You can't miss his books on Amazon and his free e-books on Syncfusion!

He wrote a JavaScript LINQ library, arrgh.js (works in IE8+, Edge, Firefox, Chrome, and probably everything else).

Check out his prize-winning articles on CodeProject as well!

Comments and Discussions