Skip to content

Instantly share code, notes, and snippets.

@jkotas
Created January 22, 2017 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkotas/9c492e62c59cb5e7220daeed587d254a to your computer and use it in GitHub Desktop.
Save jkotas/9c492e62c59cb5e7220daeed587d254a to your computer and use it in GitHub Desktop.
Lazy<T> startup
using System;
class MyG<T,U>
{
static Lazy<MyG<T,U>> s_lazy = new Lazy<MyG<T,U>>();
public static void foo(int depth)
{
if (s_lazy.IsValueCreated) return;
var dummy = s_lazy.Value;
if (depth-- == 0) return;
MyG<U,T>.foo(depth);
MyG<MyG<T,U>,T>.foo(depth);
MyG<MyG<T,U>,U>.foo(depth);
MyG<T,MyG<T,U>>.foo(depth);
MyG<U,MyG<T,U>>.foo(depth);
}
}
class My
{
static void Main()
{
int start = Environment.TickCount;
MyG<string,int>.foo(7);
int end = Environment.TickCount;
Console.WriteLine((end-start).ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment