Some notes on software development... RSS 2.0
# Thursday, 07 February 2008

This is a handy operator that can be used to replaces 'if-else' syntax therefore producing less code.
The operator is used in the form:

condition ? first_expression : second_expression;

If the condition is true then the first_expression is returned. If the condition is false the second_expression is returned.

For example:

if (string.IsNullOrEmpty(_name))
  txtName.Text = "";
  txtName.Text = _name;

can be re-written using the ternary operator like so:

txtName.Text = string.IsNullOrEmpty(_name) ? "" : _name;


MSDN ?: Operator (C# Reference)

Thursday, 07 February 2008 09:34:49 (GMT Standard Time, UTC+00:00)  #    -

Sign In
Total Posts: 116
This Year: 0
This Month: 0
This Week: 0
Comments: 36
About the author/Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2019
Hadrian Phillips

All Content © 2019, Hadrian Phillips
DasBlog theme 'Business' created by Christoph De Baene (delarou)