Last active
March 9, 2017 14:34
-
-
Save Kritner/332c9d87c0a82354a880351a43d93db8 to your computer and use it in GitHub Desktop.
Changed loop max within loop body
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 | |
{ | |
public static void Main() | |
{ | |
Thing thing = new Thing(); | |
for (int i = 0; i < thing.GetIterations; i++) | |
{ | |
thing.DoStuff(); | |
Console.WriteLine(i); | |
} | |
// Outputs: (I'm pretty suprised this works) | |
/* | |
0 | |
1 | |
2 | |
3 | |
4 | |
*/ | |
} | |
} | |
public interface IThing | |
{ | |
void DoStuff(); | |
int GetIterations { get; } | |
} | |
public class Thing : IThing | |
{ | |
private int number = 10; | |
public int GetIterations { get { return number; } } | |
public void DoStuff() | |
{ | |
number = 5; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment