Here\'s a bit of code which prints out the squares of the numbers from 0 to 9:
for (int i = 0; i < 10; i++)
Console.WriteLine(i*i);
Doin
Try this:
public static class IntExtensions
{
public static void UpTo(this int n, Action proc)
{
for (int i = 0; i < n; i++)
proc(i);
}
}
With this you could write
10.UpTo(i => Console.WriteLine(i * i));
The function I wrote is called an extension method.
At design time you notice is not a native function because it has a different icon.
Estension methods are static methods or functions included in a static class and type they work on is the first param on which you must use this
keyword.
In IntExtensions
class you could write all methods you please; grouping them inside the same static class makes you easy manage them.