Created
June 21, 2019 12:49
-
-
Save daneb/c30ff2e9ad9c122ea12af3ba3532b159 to your computer and use it in GitHub Desktop.
Type System Safe for C#
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
[Fact] | |
public void ThisIsSafe() | |
{ | |
int a = 5; | |
int b = a + 2; //OK | |
bool test = true; | |
// Error. Operator '+' cannot be applied to operands of type 'int' and 'bool'. | |
int c = a + test; | |
} | |
[Fact] | |
public void ThisIsUnSafe() | |
{ | |
var integers = new ArrayList(); | |
integers.Add(1); | |
integers.Add(2); | |
integers.Add("3"); // **PROBLEM** | |
for (int i = 0; i < integers.Count; ++i) | |
{ | |
int integer = (int)integers[i]; | |
// do something | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment