Skip to content

Commit

Permalink
Lazy calss
Browse files Browse the repository at this point in the history
  • Loading branch information
nahiandev committed Dec 5, 2024
1 parent c3a8111 commit 6f131f1
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions DomeTrain/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
namespace DomeTrain

{
class Program
{
static void Main()
{
DoStuff(1, 2, (x, y) => x + y);
Lazy<int> lazy = new(static () =>
{
const int time = 5;
for (int i = 0; i < time; i++)
{
Thread.Sleep(1000);
Console.WriteLine($"{5 - i} second(s) to generate a random number.");
}


DoStuff(3, 4, (x, y) => x * y);
return new Random().Next(1, 100);
});

DoStuff(7, 6, (x, y) => x * y);

DoStuff(7, 5, (x, y) => Convert.ToInt32(string.Join("", [x, y])));
Console.WriteLine(lazy.Value);
Console.WriteLine(lazy.Value);
Console.WriteLine(lazy.Value);
Console.WriteLine(lazy.Value);
Console.WriteLine(lazy.Value);
Console.WriteLine(lazy.Value);
Console.WriteLine(lazy.Value);
Console.WriteLine(lazy.Value);
}

private static void DoStuff(int x, int y, Calculate math_ops) => Console.WriteLine(math_ops(x, y));

delegate int Calculate(int x, int y);
}
}

0 comments on commit 6f131f1

Please sign in to comment.