Created
June 22, 2016 07:43
-
-
Save Phuseos/dee135aeed21919a0d56215171c44cb1 to your computer and use it in GitHub Desktop.
Null-conditional operators example (C#)
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
| /**Null-conditional operators example**/ | |
| //If the Text in txtBox1 is null, return 0, else return the length of the string of txtBox1. | |
| int RunMe; | |
| RunMe = txtBox1?.Text.Length ?? 0; | |
| //The above statement is the equivalent of the if statement below | |
| if (txtBox1.Text.Length != 0) RunMe = txtBox1.Text.Length; | |
| else RunMe = 0; | |
| //If the TextBox has the value ('Me@Me.com') then RunMe will have a value of 9. If it's empty, RunMe will be too. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment