Last active
December 29, 2015 17:58
-
-
Save MattRix/7707294 to your computer and use it in GitHub Desktop.
C# declaration example
This file contains hidden or 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
| //These have *identical* performance | |
| Car myCar = new Car(); | |
| //STYLE A: with declaration outside loop | |
| Car tempCarA; | |
| for(int c = 0; c<1000; c++) | |
| { | |
| tempCarA = myCar; | |
| tempCarA.Honk(); | |
| } | |
| //STYLE B: with declaration inside loop | |
| for(int c = 0; c<1000; c++) | |
| { | |
| Car tempCarB = myCar; | |
| tempCarB.Honk(); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment