c# - Learning by example - terminology (?, :, etc) -


When you were a child, have you ever asked your parents to write some words and they saw you Was told for? My first impression was always like, "OK if I can see it, I will not need it". (Yes, yes, I know phoneticity)

... Anyway, I was looking at some code and I found such an example:

  txtbx.CharacterCasing = (Checkbox checked)? Character Casing Upper: Character Casing. Normal;  

I can find out what this operation does, but obviously I can not do this for Google? Or: And I can not find them while searching for "c # operators", LINQ, Lambda Expression etc. So I have to ask this silly question so that I can start reading about it.

What are these operators?

?: , and the best way to find out here is to ask for!

  status? First_preview: second expression;  

If the condition is correct, then the first expression is evaluated and the result is created; If wrong, the second expression is evaluated and the result is created.

The assignment is very useful for readability, when the entire expression is relatively low:

  string name = string .isNullOrEmpty (user.Nickname)? User.fullname: user.Nickname  

is very simple and fast:

  string name = user.Fullname; If (! String.IsNullOrEmpty (user.Nickname)) {name = user.Nickname; }  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -