Created
August 29, 2019 18:06
-
-
Save fdrobidoux/2e36eac8b8cbc39e68febbfa18bc7d8b to your computer and use it in GitHub Desktop.
`Is` Casting in 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
/** | |
* Example with `is` that creates a casted item. | |
*/ | |
public void onSomethingHappens(object sender, EventArgs args) | |
{ | |
if (sender is XmlDocument xmlDoc) | |
{ | |
} | |
else if (sender is IDictionary<int, object> dictIntegers) | |
{ | |
foreach (KeyValuePair<int, object> kp in dictIntegers.) | |
{ | |
Console.WriteLine($"{kp.Key} => {kp.Value}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment