Skip to content

Instantly share code, notes, and snippets.

@fdrobidoux
Created August 29, 2019 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdrobidoux/2e36eac8b8cbc39e68febbfa18bc7d8b to your computer and use it in GitHub Desktop.
Save fdrobidoux/2e36eac8b8cbc39e68febbfa18bc7d8b to your computer and use it in GitHub Desktop.
`Is` Casting in C#
/**
* 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