Created
November 19, 2021 08:48
-
-
Save filmor/33c9276304cc13a94a0bc3927e2fc6a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
static int i = 0; | |
static Test test = new Test(); | |
static Test GetTest => (i % 2) == 0 ? null : test; | |
static string FuncWithSideEffect() { | |
Console.WriteLine("Called inner"); | |
return "inner"; | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("Started"); | |
Console.WriteLine("GetTest: {0}", GetTest); | |
GetTest?.Func(FuncWithSideEffect()); | |
GetTest?.Func($"{test}"); | |
i = 1; | |
Console.WriteLine("==="); | |
Console.WriteLine("GetTest: {0}", GetTest); | |
GetTest?.Func(FuncWithSideEffect()); | |
GetTest?.Func($"{test}"); | |
i = 2; | |
Console.WriteLine("==="); | |
Console.WriteLine("GetTest: {0}", GetTest); | |
GetTest?.Func(FuncWithSideEffect()); | |
GetTest?.Func($"{test}"); | |
Console.WriteLine("Done"); | |
} | |
} | |
class Test { | |
public void Func(string s) { | |
Console.WriteLine("Called Func({0})", s); | |
} | |
public override string ToString() { | |
Console.WriteLine("ToString called"); | |
return "test"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment