{"id":217,"date":"2013-08-19T23:38:41","date_gmt":"2013-08-20T02:38:41","guid":{"rendered":"http:\/\/gianfratti.com\/?p=217"},"modified":"2013-08-20T11:22:12","modified_gmt":"2013-08-20T14:22:12","slug":"o-operador-de-avaliacao-condicional","status":"publish","type":"post","link":"https:\/\/gianfratti.com\/index.php\/o-operador-de-avaliacao-condicional\/","title":{"rendered":"O operador de avalia\u00e7\u00e3o condicional &#8211; ?:"},"content":{"rendered":"<p><span style=\"font-family: Trebuchet MS; font-size: medium;\">O operador condicional <strong>(:?) <\/strong>avalia uma express\u00e3o booleana e retorna um dentre dois valores.<\/span><\/p>\n<p><span style=\"font-family: Trebuchet MS; font-size: medium;\">O formato do operador <strong>(:?)<\/strong> \u00e9 o seguinte:<\/span><\/p>\n<table width=\"450\" border=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#FFFFC4\">\n<pre><span style=\"font-family: Trebuchet MS; font-size: large;\"><strong>condi\u00e7\u00e3o ? primeira_express\u00e3o : segunda_express\u00e3o<\/strong><\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-family: Trebuchet MS; font-size: medium;\"><!--more-->Se a condi\u00e7\u00e3o for verdadeira, a primeira express\u00e3o \u00e9 avaliada e se torna o resultado, se falsa, a segunda express\u00e3o \u00e9 avaliada e se torna o resultado. Apenas uma das duas express\u00f5es \u00e9 sempre avaliada.<\/span><\/p>\n<p><span style=\"font-family: Trebuchet MS; font-size: medium;\">Abaixo temos um exemplo mostra como podemos usar o operador para reduzir a quantidade de c\u00f3digo escrita:<\/span><\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#FFFFC4\"><span style=\"font-family: Trebuchet MS;\"><span style=\"font-family: Trebuchet MS;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 static void Main(string[] args)<br \/>\n{<br \/>\nint x = 10;<br \/>\nint y = 20;<br \/>\nint maximo;<\/span><\/span><span style=\"color: #ff0000; font-family: Trebuchet MS;\"><strong>\u00a0\u00a0\u00a0\u00a0 if (x &gt; y)<br \/>\nmaximo = x;<br \/>\nelse<br \/>\nmaximo = y;<\/strong><\/span>Console.WriteLine(&#8221; M\u00e1ximo = &#8221; + maximo);<br \/>\nConsole.ReadKey();<br \/>\n}<\/td>\n<td bgcolor=\"#E2E2E2\"><span style=\"font-family: Trebuchet MS;\"><span style=\"font-family: Trebuchet MS;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 static void Main(string[] args)<br \/>\n{<br \/>\nint x = 10;<br \/>\nint y = 20;<br \/>\nint maximo;<\/span><\/span><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong><span style=\"color: #0000ff; font-family: Trebuchet MS;\"><strong>\u00a0maximo = (x &gt; y) ? x : y;<\/strong><\/span>Console.WriteLine(&#8221; M\u00e1ximo = &#8221; + maximo);<br \/>\nConsole.ReadKey();<br \/>\n}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-family: Trebuchet MS; font-size: medium;\">A seguir um exemplo que verifica se uma vari\u00e1vel \u00e9 null : Ex:<br \/>\n<\/span><span style=\"color: #0000ff; font-family: Trebuchet MS; font-size: medium;\"><strong>Valor == null ? ValorSeForNull : ValorSeNaoForNulll;<\/strong><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>O operador condicional (:?) avalia uma express\u00e3o booleana e retorna um dentre dois valores. O formato do operador (:?) \u00e9 o seguinte: condi\u00e7\u00e3o ? primeira_express\u00e3o : segunda_express\u00e3o<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-217","post","type-post","status-publish","format-standard","hentry","category-net-framework"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":3,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"predecessor-version":[{"id":220,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts\/217\/revisions\/220"}],"wp:attachment":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/tags?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}