﻿<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
><channel><title>Guanabara.info &#187; C#</title> <atom:link href="http://www.guanabara.info/category/colunas/c-colunas/feed/" rel="self" type="application/rss+xml" /><link>http://www.guanabara.info</link> <description>Podcast, vídeo aulas, PHP, HTML, SEO, Humor e Notícias todo dia</description> <lastBuildDate>Fri, 10 Feb 2012 15:41:25 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.2</generator> <language>pt-br</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /><itunes:summary>Podcast, vídeo aulas, PHP, HTML, SEO, Humor e Notícias todo dia</itunes:summary> <itunes:author>Gustavo Guanabara</itunes:author> <itunes:explicit>no</itunes:explicit> <itunes:image href="http://www.guanabara.info/podcast/images/guanacast-logo.jpg" /> <itunes:owner> <itunes:name>Gustavo Guanabara</itunes:name> <itunes:email>contato@guanabara.info</itunes:email> </itunes:owner> <managingEditor>contato@guanabara.info (Gustavo Guanabara)</managingEditor> <copyright>2006-2007</copyright> <itunes:subtitle>GuanaCast o Melhor Podcast de Tecnologia</itunes:subtitle> <itunes:keywords>podcast, tecnologia, seo, hardware, como funciona</itunes:keywords> <image><title>Guanabara.info &#187; C#</title> <url>http://www.guanabara.info/podcast/images/PodTunesPeq.jpg</url><link>http://www.guanabara.info/category/colunas/c-colunas/</link> </image> <itunes:category text="Technology"> <itunes:category text="Podcasting" /> <itunes:category text="Software How-To" /> </itunes:category> <item><title>[C#] Guidelines</title><link>http://www.guanabara.info/2008/09/c-guidelines/</link> <comments>http://www.guanabara.info/2008/09/c-guidelines/#comments</comments> <pubDate>Sun, 07 Sep 2008 20:46:56 +0000</pubDate> <dc:creator>Renan Vieira</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Colunas]]></category> <category><![CDATA[CSharp]]></category> <category><![CDATA[Guidelines]]></category><guid
isPermaLink="false">http://www.guanabara.info/?p=4496</guid> <description><![CDATA[
Fala pessoal deixamos os códigos de lado por um momento, e vamos falar sobre as Guidelines, ou diretrizes de programação.
As Guidelines são regras usadas para quando vocês está desenvolvedo algo. A idéia é deixar o código o mais legível possível, e com isso deixar o código com um indice de manutenibilidade alto.
Irei indicar apenas as básicas, relacionadas a nomeclatura de método e propriedades.PascalCasing e CamelCasing
Os nomes dos metodos e propriedades devem seguir o chamado PascalCasing, ou seja, deve ter  a inicial de cada palavra maiuscula.
Exemplos://Métodos
public void GetNumber();
public void GetName();
public void GetCustumerNameById()
public void SetFlag();//Propriedades
public int Number{get;set;}
public decimal UnitPrice{get;set;}
public string Name{get;set;}
public int NumberOfWheels{get;set;}Já os parametros e váriaveis locais deve seguir o chamado CamelCasing, ou seja, a primeira letra deve ser minuscula e as iniciais das outras palavras devem ser maiusculas.
Ex:public string GetNameByLastName(string lastName);
public int GetVehicleType(int numberOfWheels);
public decimal GetUnitPrice(string productName);Veja o casing dos parametros das funções. O mesmo deve ser aplicado para as varíaveis locais.
Metodos e verbos?
Pois é. Segundo essa guideline TODOS os metodos devem iniciar com verbos. Se você vai adicionar algo, use Add, se vai pegar algo de algum lugar, use Get, se vai atribuir alguma coisa a algo, use Set, e assim vai.
Ex.:// Pega um numero
public int GetNumber();// Adiciona um numero
public int AddNumber( int id);//Encontra um numero em uma coleção(array)
public int FindNumberInCollection(int id);Existe uma outra guideline que diz: &#8220;Todas as propriedades booleanas devem iniciar com Has, Can ou Is&#8221;
Ex.://Exemplos
public bool IsAlive{get;set;}
private bool CanRead{get;set;}
protected bool HasRows{get;set;}Bem legível não?
Ah! Quase esqueci, existe uma Guideline que diz ; &#8220;Todos os metodos, propriedades, variaveis, enfim todos os nomes devem estar em inglês&#8221;.
E essas são apenas algumas das guidelines de nomeclatura e podem ser aplicadas para qualquer linguagem. É impressionante como essas regrinhas simples deixam um código mais legível e fácil de entender.
Se quiserem estudar mais sobre: http://msdn.microsoft.com/en-us/library/ms229042.aspx
E não é apenas para programação que existem, [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://www.guanabara.info/wp-content/uploads/2008/05/csharpbanner.jpg" alt="" /></p><p>Fala pessoal deixamos os códigos de lado por um momento, e vamos falar sobre as Guidelines, ou diretrizes de programação.</p><p>As Guidelines são regras usadas para quando vocês está desenvolvedo algo. A idéia é deixar o código o mais legível possível, e com isso deixar o código com um indice de manutenibilidade alto.</p><p>Irei indicar apenas as básicas, relacionadas a nomeclatura de método e propriedades.</p><p><span
id="more-4496"></span></p><h2>PascalCasing e CamelCasing</h2><p>Os nomes dos metodos e propriedades devem seguir o chamado <strong>PascalCasing</strong>, ou seja, deve ter  a inicial de cada palavra maiuscula.</p><p>Exemplos:</p><div
style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #008000;">//Métodos</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> GetNumber();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> GetName();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> GetCustumerNameById()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> SetFlag();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #008000;">//Propriedades</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> Number{get;set;}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">decimal</span> UnitPrice{get;set;}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> Name{get;set;}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> NumberOfWheels{get;set;}</pre></div></div><p>Já os parametros e váriaveis locais deve seguir o chamado <strong>CamelCasing</strong>, ou seja, a primeira letra deve ser minuscula e as iniciais das outras palavras devem ser maiusculas.</p><p>Ex:</p><div
style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> GetNameByLastName(<span style="color: #0000ff;">string</span> lastName);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> GetVehicleType(<span style="color: #0000ff;">int</span> numberOfWheels);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">decimal</span> GetUnitPrice(<span style="color: #0000ff;">string</span> productName);</pre></div></div><p>Veja o casing dos parametros das funções. O mesmo deve ser aplicado para as varíaveis locais.</p><h2>Metodos e verbos?</h2><p>Pois é. Segundo essa guideline <strong>TODOS</strong> os metodos devem iniciar com verbos. Se você vai adicionar algo, use <em>Add</em>, se vai pegar algo de algum lugar, use <em>Get</em>, se vai atribuir alguma coisa a algo, use <em>Set</em>, e assim vai.</p><p>Ex.:</p><div
style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #008000;">// Pega um numero</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> GetNumber();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #008000;">// Adiciona um numero</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> AddNumber( <span style="color: #0000ff;">int</span> id);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #008000;">//Encontra um numero em uma coleção(array)</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> FindNumberInCollection(<span style="color: #0000ff;">int</span> id);</pre></div></div><p>Existe uma outra guideline que diz: &#8220;Todas as propriedades booleanas devem iniciar com <strong>Has</strong>, <strong>Can</strong> ou <strong>Is</strong>&#8221;</p><p>Ex.:</p><div
style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #008000;">//Exemplos</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> IsAlive{get;set;}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">bool</span> CanRead{get;set;}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">bool</span> HasRows{get;set;}</pre></div></div><p>Bem legível não?</p><p>Ah! Quase esqueci, existe uma Guideline que diz ; <strong>&#8220;Todos os metodos, propriedades, variaveis, enfim todos os nomes devem estar em inglês&#8221;.</strong></p><p>E essas são apenas algumas das guidelines de nomeclatura e podem ser aplicadas para qualquer linguagem. É impressionante como essas regrinhas simples deixam um código mais legível e fácil de entender.</p><p>Se quiserem estudar mais sobre: <a
title="http://msdn.microsoft.com/en-us/library/ms229042.aspx" href="http://msdn.microsoft.com/en-us/library/ms229042.aspx">http://msdn.microsoft.com/en-us/library/ms229042.aspx</a></p><p>E não é apenas para programação que existem, existe Guidelines para Banco de dados, XML e muitas outras linguagens.</p> ]]></content:encoded> <wfw:commentRss>http://www.guanabara.info/2008/09/c-guidelines/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> <item><title>[C#] Parte III &#8211; Estruturas de Repeti&#231;&#227;o e Vetores</title><link>http://www.guanabara.info/2008/08/c-parte-iii-estruturas-de-repetio-e-vetores/</link> <comments>http://www.guanabara.info/2008/08/c-parte-iii-estruturas-de-repetio-e-vetores/#comments</comments> <pubDate>Tue, 05 Aug 2008 12:00:59 +0000</pubDate> <dc:creator>Renan Vieira</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Colunas]]></category> <category><![CDATA[Array]]></category> <category><![CDATA[CSharp]]></category> <category><![CDATA[Loop]]></category> <category><![CDATA[Microsoft]]></category> <category><![CDATA[Mula]]></category><guid
isPermaLink="false">http://www.guanabara.info/?p=3969</guid> <description><![CDATA[
Olá galera!
Chegamos a mais uma aula-post de C# do Guanabara.INFO, nesse post iremos aprender a sintaxe das estruturas de repetição, ou laços de repetição e também uma pequena introdução à arrays(vetores).
Abram seus Visual C# Express, criem uma ConsoleApplication e mãos a obra.A primeira estrutura de repetição que iremos estudar é o WHILE.
A sintaxe é moleza!while(CONDIÇÃO)
{
//Código
}Vamos fazer algo mais construtivo!using System;
namespace Loop{
class Program{
static void Main(string[] args){
int numero = 1;
while(numero &#60; 15){
Console.WriteLine("Luiz é um MULA!");
numero++;
}
}
}
}Vamos à explicação da bagaça!
ENQUANTO numero FOR MENOR QUE 15
ESCREVA &#8220;Luiz é uma MULA!&#8221;
numero &#60;- numero +1
Simples não? Vamos agora ao laço FOR
Sintaxe:for(INICIALIZAÇÃO;CONDIÇÃO;SALTO){
//Código
}Novamente, vamos a algo mais construtivo; Uma tabuada:using System;
namespace Loop{
class Program{
static void Main(string[] args){
int tabuada = 2;
for(int numero = 1;numero &#60;= 10;numero++){
Console.WriteLine("{0} + {1} = {2}",tabuada,numero,tabuada*numero);
}
}
}
}OPA! Aí temos mais novidades! [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: center;"><img
class="aligncenter" src="http://www.guanabara.info/wp-content/uploads/2008/05/csharpbanner.jpg" alt="" /></p><p>Olá galera!</p><p>Chegamos a mais uma <em>aula-post</em> de <strong>C#</strong> do <strong>Guanabara.INFO,</strong> nesse post iremos aprender a sintaxe das <strong>estruturas de repetição</strong>, ou <em>laços de repetição</em> e também uma pequena introdução à <strong>arrays</strong>(<em>vetores</em>).</p><p>Abram seus <strong><a
title="Visual C# Express" href="http://www.microsoft.com/express/download/#webInstall" target="_blank">Visual C# Express</a></strong>, criem uma <strong>ConsoleApplication</strong> e mãos a obra.</p><p><span
id="more-3969"></span></p><p>A primeira estrutura de repetição que iremos estudar é o <strong>WHILE.</strong></p><p>A sintaxe é moleza!</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">while</span>(CONDIÇÃO)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #008000;">//Código</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">}</pre></div></div><p>Vamos fazer algo mais construtivo!</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">using</span> System;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">namespace</span> Loop{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff;">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main(<span style="color: #0000ff;">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff;">int</span> numero = 1;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff;">while</span>(numero &lt; 15){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080;">"Luiz é um MULA!"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                numero++;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">}</pre></div></div><p>Vamos à explicação da bagaça!</p><p><strong>ENQUANTO</strong> numero <strong>FOR MENOR QUE</strong> 15<br
/> <strong>ESCREVA</strong> &#8220;<em>Luiz é uma MULA!</em>&#8221;<br
/> numero <strong>&lt;-</strong> numero +1</p><p>Simples não? Vamos agora ao laço <strong>FOR</strong></p><p><strong>Sintaxe:</strong></p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">for</span>(INICIALIZAÇÃO;CONDIÇÃO;SALTO){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #008000;">//Código</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre></div></div><p>Novamente, vamos a algo mais construtivo; Uma tabuada:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">using</span> System;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">namespace</span> Loop{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff;">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main(<span style="color: #0000ff;">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff;">int</span> tabuada = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> numero = 1;numero &lt;= 10;numero++){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080;">"{0} + {1} = {2}"</span>,tabuada,numero,tabuada*numero);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre></div></div><p>OPA! Aí temos mais novidades! Mas antes, vamos &#8220;<em>algoritmizar</em>&#8221; a sintaxe do <strong>FOR.</strong></p><p><strong>PARA </strong><em>numero</em> <strong>IGUAL A</strong> <em>1</em><strong>;</strong> <strong>ENQUANTO</strong> <em>numero</em> <strong>FOR MENOR OU IGUAL A</strong><em> 10</em><strong>;</strong><em> <strong>INCREMENTANDO</strong> 1</em><strong> EM</strong><em> numero </em><strong>FAÇA &#8230;</strong></p><p>Temos ali no <em>Console.WriteLine</em>, uma novidade. O seguinte código é apresentado:</p><p><em><strong>Console.WriteLine(<span
style="color: #006080;">&#8220;{0} + {1} = {2}&#8221;</span>,tabuada,numero,tabuada*numero);</strong></em></p><p><em>Vamos destrinchá-lo:</em></p><p>String passada<em>: &#8220;{0} + {1} = {2}&#8221;<br
/> </em>Variaveis passadas após a string : <em>tabuada,numero,tabuada*numero</em></p><p><em>É coisa simples! Olhem só!</em></p><p><strong>{0}</strong><em> =&gt; Equivale ao primeiro parametro depois da string que será exibida, no nosso caso equivale a variavél <strong>tabuada</strong>.</em></p><p><strong>{1}</strong> <em>=&gt; Equivale ao segundo parametro depois da string que será exibida, no nosso caso equivale a variavél <strong>numero</strong>.</em></p><p><em><strong>{2}</strong> =&gt; Equivale ao primeiro parametro depois da string que será exibida, no nosso caso equivale ao resultado da multiplicação entre as variavéis <strong>tabuada</strong> e <strong>numero</strong>.</em></p><h2>Vetores ou Arrays</h2><p>Quem já passou pelo Ensino Médio concerteza já ouviu falar de vetores e matrizes. Na programação os vetores são chamados de <strong>array. </strong></p><p>Segundo a <strong>Wikipedia</strong> <em>Vetores</em> no contexto da <em>geometria</em>:</p><blockquote><p>Vetor é um objeto geométrico que possui uma magnitude e uma direção. Um vetor é frequentemente representado por um segmento de reta unindo o ponto inicial A ao ponto final B e é denotado</p></blockquote><p>Também a <strong>Wikipedia</strong>, dessa vez no contexto de<em> programação de computadores</em>:</p><blockquote><p>Um array, também conhecido como vetor ou lista (para arrays uni-dimensionais) ou matriz (para arrays bi-dimensionais), é uma das mais simples estruturas de dados. Os arrays mantêm uma série de elementos de dados, geralmente do mesmo tamanho e tipo de dados. Elementos individuais são acessados por sua posição no array.</p></blockquote><p>Os <strong>arrays</strong> são estruturas de dados simples, que de uma forma sucinta, podemos dizer que nos permite armazenar mais de uma informação em uma variável. Os elementos de um <strong>array</strong> são acessados através de um <em>índice</em>, podendo ser um <em>índice</em> númerico(<em><strong>int</strong></em>) ou texto(<strong><em>string</em></strong>).</p><p>Geralmente, uma variavel do tipo inteiro só pode receber um número, veja o exemplo:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero = 1;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">int</span> Idade = 17;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">int</span> ABC = 130;</pre></div></div><p>E se quisermos amazenar 10 números? <strong>FACIL</strong>! <em>10 variavéis né</em>?</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero1 = 1;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero2 = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero3 = 3;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero4 = 4;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero5 = 5;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero6 = 6;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero7 = 7;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero8 = 8;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero9 = 9;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numero10 = 10;</pre></div></div><p><strong>OBS</strong>.: <em>ÊTA! Gambiarra!</em></p><p>Não seria mais fácil e legível assim?</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">int</span> Numeros[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};</pre></div></div><p>Pronto! Temos o tal <strong>Array</strong> em <strong>C#</strong> .  <img
src='http://www.guanabara.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Vamos ao código que faz uso efetivo de um <strong>array</strong> <em>uni-dimensional</em>:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">using</span> System;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">namespace</span> CSharpArrays{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main(<span style="color: #0000ff;">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff;">int</span> Numeros = {1, 2, 3, 4, 5};</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff;">int</span> i = 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff;">for</span>(i = 0;i&lt;=Numeros.Length;i++){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080;">"{0}"</span>, Numeros[i]);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre></div></div><p><strong>Dissecando o exemplo:</strong><br
/> Vemos alí que declaramos um <strong>array</strong> de <em>números inteiros</em> chamado <strong>Numeros</strong>, e<strong> </strong>colocamos como elementos desse <strong>array</strong>, os números de 1 a 5.</p><p>Logo depois, iniciamos um laço <strong>FOR</strong>, dizendo que enquanto a variável <strong>i</strong> for menor que o número total de elementos no array <strong>Numeros</strong> (<em>O valor total de elementos no vetor é retornado pela propriedade <strong>Length</strong></em>), incrementando +1 na variável <strong>i</strong> a cada loop.</p><p>Dentro do <em>laço</em> <strong>FOR</strong> temos uma saída para o console, indicando <strong>Numeros[i].</strong></p><p><strong>Entendendo o Numeros[i]</strong></p><p>Cada elemento em um <strong>array</strong> corresponde a um <em>índice</em>, <em>índice</em> esse que pode ser tanto númerico quanto <strong>string</strong>, mas no nosso exemplo ele será apenas númerico. A cada volta no laço FOR, i terá um valor diferente, sempre maior que 0 e menor ou igual ao total de elementos no vetor, que no nosso exemplo é 5.</p><p>No C#, <strong>arrays</strong> têm índice <strong>ZERO</strong>, ou seja, o primeiro <em>índice</em> númerico de um <strong>array</strong> SEMPRE será <strong>ZERO, </strong>por isso no código de exemplo acima a variável <strong>i</strong> inicia o <em>loop</em> com o valor <strong>0</strong>.</p><p>Mais um exemplo, para garantir o aprendizado:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">namespace</span> Arrays{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff;">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main(<span style="color: #0000ff;">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff;">string</span>[] Nomes = {<span style="color: #006080;">"Renan"</span>, <span style="color: #006080;">"Gustavo"</span>, <span style="color: #006080;">"Luiz Ricardo"</span>, <span style="color: #006080;">"Rafael"</span>, <span style="color: #006080;">"Rodrigo"</span>};</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i = 0; i &lt;= Nomes.Length; i++){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080;">"{0}"</span>,Nomes[i]);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">}</pre></div></div><p>Vamos simplificar, AINDA MAIS, esse último exemplo?</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff;">namespace</span> Arrays{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff;">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main(<span style="color: #0000ff;">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff;">string</span>[] Nomes = {<span style="color: #006080;">"Renan"</span>, <span style="color: #006080;">"Gustavo"</span>, <span style="color: #006080;">"Luiz Ricardo"</span>,<span style="color: #006080;">"Rafael"</span>,<span style="color: #006080;">"Rodrigo"</span>};</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff;">foreach</span>(<span style="color: #0000ff;">string</span> nome <span style="color: #0000ff;">in</span> Nomes){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(nome);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre></div></div><p>Apresento a vocês o <em>laço de repetição</em> chamado <strong>foreach</strong> , ele é muito usado para trabalhar com <strong>arrays</strong>, como vemos no exemplo acima.</p><p>Vamos &#8220;<em>algoritmiza-lo</em>&#8220;:</p><p><strong>PARA CADA</strong> <em>string nome</em> <strong>EM</strong> <em>Nomes</em> <strong>FAÇA &#8230;</strong></p><p>Assim o <strong>foreach</strong> percorre cada elemento do <strong>array</strong> e retornando seus respectivos valores, como <em>string</em>. Lembrando que, se não for um <strong>array</strong> de <em>string</em> o código acima irá resultar em um erro. O tipo da variável que irá receber os valores dos elementos deverá ser compatível com tipo do <strong>array</strong>.</p><p>Bem mais fácil assim, não? <img
src='http://www.guanabara.info/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p><strong>Na próxima semana <em>Vetores Multi-dimensionais</em>.</strong></p><p><em>Até a próxima, e</em> <strong>WELCOME TO THE .NET WORLD</strong>.</p><p><strong><span
style="color: #004080;">.:: Links Utéis ::.</span></strong></p><p><strong></strong></p><ul><li><a
href="http://www.guanabara.info/?p=2757" target="_blank">Coluna C# &#8211; Parte 1</a></li><li><a
href="http://www.guanabara.info/?p=3957" target="_blank">Coluna C# &#8211; Parte 2</a></li><li><a
href="http://www.guanabara.info/?p=2747" target="_blank">Podcast Episódio 24 &#8211; Evolução da linguagem C</a></li><li><a
href="http://www.guanabara.info/?p=1922" target="_blank">Podcast Episódio 19 &#8211; Algoritmos Parte 1</a></li><li><a
href="http://www.guanabara.info/?p=2299" target="_blank">Podcast Episódio 21 &#8211; Algoritmos Parte 2</a></li><li><a
href="http://www.guanabara.info/?p=2852" target="_blank">Podcast Episódio 25 &#8211; Algoritmos Parte 3</a></li><li><a
href="http://www.guanabara.info/?p=3393" target="_blank">Podcast Episódio 29 &#8211; Algoritmos Parte 4</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://www.guanabara.info/2008/08/c-parte-iii-estruturas-de-repetio-e-vetores/feed/</wfw:commentRss> <slash:comments>20</slash:comments> </item> <item><title>[C#] Parte II &#8211; Variav&#233;is e Estrutura condicional</title><link>http://www.guanabara.info/2008/07/c-parte-ii-variavis-e-estrutura-condicional/</link> <comments>http://www.guanabara.info/2008/07/c-parte-ii-variavis-e-estrutura-condicional/#comments</comments> <pubDate>Mon, 28 Jul 2008 10:30:17 +0000</pubDate> <dc:creator>Renan Vieira</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Colunas]]></category> <category><![CDATA[Aulas]]></category> <category><![CDATA[CSharp]]></category> <category><![CDATA[Microsoft]]></category><guid
isPermaLink="false">http://www.guanabara.info/?p=3957</guid> <description><![CDATA[&#160;
Olá galera,
Vou começar pedindo desculpas pela demora do post.
No artigo anterior, vimos o famoso Olá Mundo em C#, e uma rápida explicação&#160; de como o C# e a plataforma .NET funcionam.
Então abram seus Visual C# Express, criem um projeto do tipo Console Application e vamos à sintaxe!
Continue lendo.Declaração e tipos de variavéis
No C# a declaração de varíaveis é obrigatória, assim como a declaração de seus tipos.
Os tipo de variáveis mais utilizados são:
&#160;int &#8211; Número Inteiro de 32-bits&#160;byte &#8211; Número inteiro de 8-bits &#160;double &#8211; Número de ponto-flutuante de 64bits &#160;bool &#8211; Valor Booleano, verdadeiro ou falso. &#160;string &#8211; Texto, número ou qualquer caracter.
Vejamos um exemplo:namespace OlaMundo
{
class Program{
static void Main(string[] args){
string Texto = "Olá Mundo";
System.Console.WriteLine(Texto);
}
}
}Como podemos ver na imagem acima, a declaração de variaveis segue o seguinte formato.
[TIPO] [NOME DA VARIAVEL] = [VALOR];
ou
[TIPO] [NOME DA VARIAVEL];
Vale lembrar que o C# é case-sensitive, então a varíavel &#8220;Texto&#8221; é diferente de &#8220;texto&#8221; e &#8220;System.Console.WriteLine()&#8221; é diferente de &#8220;system.console.writeline()&#8221;.
Só para fixarmos, aí vai mais um exemplo:using System;
namespace OlaMundo{
class Program{
static void Main(string[] args){
int Numero = 2;
int OutroNumero = 2;
int MaisUmNumero = Numero + OutroNumero;
[...]]]></description> <content:encoded><![CDATA[<p><img
src="http://www.guanabara.info/wp-content/uploads/2008/05/csharpbanner.jpg">&nbsp;<p>Olá galera,<p>Vou começar pedindo desculpas pela demora do post. <img
src='http://www.guanabara.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><p>No artigo anterior, vimos o famoso <em>Olá Mundo</em> em <strong>C#,</strong> e uma rápida explicação&nbsp; de como o <strong>C#</strong> e a plataforma <strong>.NET</strong> funcionam.<p>Então abram seus <strong><a
href="http://www.microsoft.com/express/download/" target="_blank">Visual C# Express</a></strong>, criem um projeto do tipo <strong>Console Application</strong> e <strong>vamos à sintaxe!</strong><p><strong><em>Continue lendo.</em></strong></p><p><span
id="more-3957"></span></p><h2>Declaração e tipos de variavéis</h2><p>No C# a declaração de varíaveis é obrigatória, assim como a declaração de seus tipos.<p> Os tipo de variáveis mais utilizados são:<p>&nbsp;<strong>int</strong> &#8211; Número Inteiro de 32-bits<br
/>&nbsp;<strong>byte</strong> &#8211; Número inteiro de 8-bits <br
/>&nbsp;<strong>double</strong> &#8211; Número de ponto-flutuante de 64bits <br
/>&nbsp;<strong>bool</strong> &#8211; Valor Booleano, verdadeiro ou falso. <br
/>&nbsp;<strong>string</strong> &#8211; Texto, número ou qualquer caracter.<p> Vejamos um exemplo:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">namespace</span> OlaMundo</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">string</span> Texto = <span style="color: #006080">"Olá Mundo"</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            System.Console.WriteLine(Texto);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre></div></div><p>Como podemos ver na imagem acima, a declaração de variaveis segue o seguinte formato.</p><p><strong> [TIPO] [NOME DA VARIAVEL] = [VALOR];</strong></p><p>ou</p><p><strong>[TIPO] [NOME DA VARIAVEL];</strong></p><p>Vale lembrar que o C# é case-sensitive, então a varíavel &#8220;Texto&#8221; é diferente de &#8220;texto&#8221; e &#8220;<em>System.Console.WriteLine()&#8221;</em> é diferente de &#8220;<em>system.console.writeline()&#8221;.</em></p><p>Só para fixarmos, aí vai mais um exemplo:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">using</span> System;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">namespace</span> OlaMundo{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">int</span> Numero = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">int</span> OutroNumero = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">int</span> MaisUmNumero = Numero + OutroNumero;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            Console.WriteLine(MaisUmNumero);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">}</pre></div></div><p>Nessa imagem, temos 3 varíaveis.</p><p>As variaveis do tipo inteiro: <em>Numero</em>,<em>OutroNumero</em> recebem o valor 2. A variavel <em>MaisUmNumero</em> recebe a soma das variaveis <em>Numero</em> e <em>OutroNumero</em>.</p><p><strong>NOTA</strong>: Note que na primeira linha do código eu usei o comando using para importar o namespace <em>System</em>, com isso não será necessário utilizar o <em>System.Console.WriteLine</em>, somente <em>Console.WriteLine</em>, como é mostrado na linha 12. Se você não entendeu, isso será explicado mais detalhadamente nos próximos artigos.</p><h2>Estrutura Condicional &#8211; IF/ELSE e SWITCH/CASE</h2><p>A estrutura condicional do <strong>C#</strong> é bem parecida com a do PHP, JAVA, C/C++ e derivados.</p><p>Sintaxe:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">if</span>(CONDIÇÃO)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #008000">//Código</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">}<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(CONDIÇÃO)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #008000">//Código</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}<span style="color: #0000ff">else</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #008000">//Código</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">} </pre></div></div><p><strong>Operadores lógicos:</strong></p><table
border="0" cellspacing="0" cellpadding="2" width="400"><tbody><tr><td
valign="top" width="200">&amp;&amp;</td><td
valign="top" width="200">E</td></tr><tr><td
valign="top" width="200">||</td><td
valign="top" width="200">OU</td></tr><tr><td
valign="top" width="200">==</td><td
valign="top" width="200">Igual</td></tr><tr><td
valign="top" width="200">!=</td><td
valign="top" width="200">Diferente</td></tr></tbody></table><p>&nbsp;</p><p><strong>Operadores aritiméticos:</strong></p><table
border="0" cellspacing="0" cellpadding="2" width="400"><tbody><tr><td
valign="top" width="200">/</td><td
valign="top" width="200">Divisão</td></tr><tr><td
valign="top" width="200">+</td><td
valign="top" width="200">Soma</td></tr><tr><td
valign="top" width="200">-</td><td
valign="top" width="200">Subtração</td></tr><tr><td
valign="top" width="200">*</td><td
valign="top" width="200">Multiplicação</td></tr><tr><td
valign="top" width="200">%</td><td
valign="top" width="200">Resto da divisão</td></tr></tbody></table><p>&nbsp;<p>Vejamos alguns exemplos:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">using</span> System;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">namespace</span> OlaMundo{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">int</span> Numero = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">int</span> OutroNumero = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">if</span>(Numero &gt; OutroNumero){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080">"Numero é Maior"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            }<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(OutroNumero &gt; Numero){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080">"OutroNumero é maior."</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            }<span style="color: #0000ff">else</span>{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080">"São iguais"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">}</pre></div></div><p>Dica: Se dentro de um IF/ELSE tiver somente uma linha, o uso das {} é opcional. Veja abaixo:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">using</span> System;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">namespace</span> OlaMundo{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">int</span> Numero = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">int</span> OutroNumero = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">if</span>(Numero &gt; OutroNumero)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080">"Numero é Maior"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(OutroNumero &gt; Numero)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080">"OutroNumero é maior."</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">else</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                Console.WriteLine(<span style="color: #006080">"São iguais"</span>);           </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre></div></div><p>Dica²: No C# também existe o &#8220;IF-Inline&#8221;.</p><p><strong>CONDIÇÃO ? EXPRESSÃO1 : EXPRESSÃO2;</strong><br
/>Se a CONDIÇÃO for verdadeira, é retornada a EXPRESSÃO1, caso contrário a EXPRESSÃO2 é retornada. <br
/>Veja um exemplo abaixo.</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">using</span> System;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">namespace</span> OlaMundo{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">class</span> Program{        </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">int</span> Numero = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">int</span> OutroNumero = 3;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">int</span> MaisUmNumero = Numero &gt; OutroNumero ? Numero : OutroNumero;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            Console.WriteLine(MaisUmNumero);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }    </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre></div></div><p>O Código acima irá retornar 3.</p><h3>Switch/Case</h3><p>Sintaxe:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 96.36%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 177px; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">switch</span>(VARIAVEL)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">case</span> VALOR:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #008000">//Faz algo se VARIAVEL for igual ao VALOR</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">break</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">default</span>:    <span style="color: #008000">//(OPCIONAL)</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #008000">//Faz algo se VARIAVEl não for igual a nenhum CASE</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">break</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">} </pre></div></div><p>No Switch você pode ter quantos case você quiser.</p><p>Vamos a um exemplo:</p><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">using</span> System;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">namespace</span> OlaMundo{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">int</span> Numero = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">switch</span>(Numero){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                <span style="color: #0000ff">case</span> 1:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                    Console.WriteLine(<span style="color: #006080">"Numero é igual a 1"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                    <span style="color: #0000ff">break</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                <span style="color: #0000ff">case</span> 2:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                    Console.WriteLine(<span style="color: #006080">"Numero é igual a 2"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                    <span style="color: #0000ff">break</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                <span style="color: #0000ff">case</span> 3:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                    Console.WriteLine(<span style="color: #006080">"Numero é igual a 3"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                    <span style="color: #0000ff">break</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre></div></div><div
style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><div
style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">using</span> System;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">namespace</span> OlaMundo{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">class</span> Program{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">int</span> Numero = 2;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">switch</span>(Numero){</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                <span style="color: #0000ff">case</span> 1:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                <span style="color: #0000ff">case</span> 2:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                <span style="color: #0000ff">case</span> 3:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                    Console.WriteLine(<span style="color: #006080">"Numero é 1,2 ou 3"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                    <span style="color: #0000ff">break</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                <span style="color: #0000ff">default</span>:</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                    Console.WriteLine(<span style="color: #006080">"Numero não é 1, nem 2, muito menos 3"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                    <span style="color: #0000ff">break</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">}</pre></div></div><p>No código acima, se Numero for igual a 1,2 ou 3, o texto &#8220;O valor é 1,2 ou 3.&#8221; será exibido, caso contrário</p><p>Muita gente se pergunta quando utilizar o <strong>Switch</strong> e quando utilizar o <strong>If</strong>, é bem simples. O <strong>Switch</strong> é recomendado para quando você sabe exatamente qual o valor a variavel terá, e o <strong>If</strong> quando você quiser realizar um teste lógico ou um teste aritimetico onde o valor não é exatamente conhecido.</p><p>Bom, acho que é só! Na próxima aprenderemos as estrutura de repetição e como trabalhar com vetores no <strong>C#.</strong></p><p>Até a próxima e <strong><em>Welcome To The .NET WORLD</em></strong>!</p><p><strong>.:: Links Utéis ::.</strong></p><ul><li><a
href="http://www.guanabara.info/?p=2757" target="_blank">Coluna C# &#8211; Parte 1</a></li><li><a
href="http://www.guanabara.info/?p=2747" target="_blank">Podcast Episódio 24 &#8211; Evolução da linguagem C</a></li><li><a
title="Podcast Epis&oacute;dio 19 - Algoritmos Parte 1" href="http://www.guanabara.info/?p=1922" target="_blank">Podcast Episódio 19 &#8211; Algoritmos Parte 1</a></li><li><a
href="http://www.guanabara.info/?p=2299" target="_blank">Podcast Episódio 21 &#8211; Algoritmos Parte 2</a></li><li><a
href="http://www.guanabara.info/?p=2852" target="_blank">Podcast Episódio 25 &#8211; Algoritmos Parte 3</a></li><li><a
href="http://www.guanabara.info/?p=3393" target="_blank">Podcast Episódio 29 &#8211; Algoritmos Parte 4</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://www.guanabara.info/2008/07/c-parte-ii-variavis-e-estrutura-condicional/feed/</wfw:commentRss> <slash:comments>26</slash:comments> </item> <item><title>[C#] Olá, Mundo!</title><link>http://www.guanabara.info/2008/05/c-ola-mundo/</link> <comments>http://www.guanabara.info/2008/05/c-ola-mundo/#comments</comments> <pubDate>Tue, 13 May 2008 03:08:35 +0000</pubDate> <dc:creator>Luiz Ricardo Freitas</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Colunas]]></category> <category><![CDATA[Desenvolvimento]]></category> <category><![CDATA[Curso]]></category> <category><![CDATA[Programação]]></category><guid
isPermaLink="false">http://www.guanabara.info/?p=2757</guid> <description><![CDATA[
OLÁ, AMANTES DA PROGRAMAÇÃO! Estamos começando hoje mais uma empreitada do site Guanabara.Info. Quem ouviu o Podcast 24 sobre a evolução da Linguagem C, já sabe o que é. UM CURSO DE C# feito com muita dedicação para todos os visitantes assíduos e sedentos por novas informações.
Para quem ainda não tem muita experiência em programação ou ainda não conhece muita coisa sobre essa poderosíssima linguagem de programação, recomendamos antes os seguintes podcasts:Episódio 19 &#8211; Construindo Algoritmos (Parte I)
Episódio 21 &#8211; Construindo Algoritmos (Parte II)
Episódio 24 &#8211; Evolução da Linguagem CEsperamos corresponder às expectativas e tornar essa coluna um verdadeiro sucesso em muito pouco tempo, incentivando sempre o surgimento de novos programadores para esse mercado que está com as portas abertas para os profissionais competentes. Clique em Leia+ e vamos começar!Nessa primeira aula vamos dar uma reforçada em toda a teoria que foi falada no PodCast 24, esperamos sanar algumas dúvidas referentes à plataforma e à linguagem. Lets Go!
O .NET Framework é um componente integrado ao Windows que suporta a execução e o desenvolvimento de uma nova geração de aplicações e web services. Segundo sua documentação, o .NET Framework tem os seguintes objetivos:Prover      um ambiente consistente de programação orientada a objeto
Executar código que minimiza o desenvolvimento de      software e conflitos de verão
Eliminar os problemas de desempenho gerados por linguagens      de script
Aproveitar      o conhecimento do programador em diferentes tipos de aplicações, como      aplicações Windows ou web
Construir      toda a comunicação em padrões reconhecidos pela indústria para que o .NET Framework possa se      integrar com qualquer tipo de códigoExistem dois componentes principais na plataforma .NET : o Common Language [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: center;"><a
href="http://www.guanabara.info/?p=2757#more-2757"><img
class="alignnone size-medium wp-image-2758 aligncenter" title="Curso de C#" src="http://www.guanabara.info/wp-content/uploads/2008/05/csharpbanner.jpg" alt="" /></a></p><p
style="text-align: justify;"><span
style="color: #800000;"><strong>OLÁ, AMANTES DA PROGRAMAÇÃO!</strong></span> Estamos começando hoje mais uma empreitada do site Guanabara.Info. Quem ouviu o <em>Podcast 24 sobre a evolução da Linguagem C, </em>já sabe o que é. <strong>UM CURSO DE C#</strong> feito com muita dedicação para todos os visitantes assíduos e sedentos por novas informações.</p><p
style="text-align: justify;">Para quem ainda não tem muita experiência em programação ou ainda não conhece muita coisa sobre essa poderosíssima linguagem de programação, recomendamos antes os seguintes podcasts:</p><ul><li><strong><a
href="http://www.guanabara.info/?p=1922" target="_blank">Episódio 19 &#8211; Construindo Algoritmos (Parte I)</a></strong></li><li><a
href="http://www.guanabara.info/?p=2299" target="_blank"><strong>Episódio 21 &#8211; Construindo Algoritmos (Parte II)</strong></a></li><li><a
href="http://www.guanabara.info/?p=2747" target="_blank"><strong>Episódio 24 &#8211; Evolução da Linguagem C</strong></a></li></ul><p
style="text-align: justify;">Esperamos corresponder às expectativas e tornar essa coluna um verdadeiro sucesso em muito pouco tempo, incentivando sempre o surgimento de novos programadores para esse mercado que está com as portas abertas para os profissionais competentes. Clique em <strong>Leia+</strong> e vamos começar!</p><p
style="text-align: justify;"><span
id="more-2757"></span></p><p>Nessa primeira aula vamos dar uma reforçada em toda a teoria que foi falada no PodCast 24, esperamos sanar algumas dúvidas referentes à plataforma e à linguagem. <em>Lets Go</em>!</p><p
id="jy:q14" class="MsoNormal">O <strong>.NET Framework</strong> é um componente integrado ao Windows que suporta a execução e o desenvolvimento de uma nova geração de aplicações e <em
id="jy:q12">web services</em>. Segundo sua documentação, o <strong>.NET <span
id="jy:q13" lang="EN-US">Framework</span></strong> tem os seguintes objetivos:</p><ul
id="jy:q16" style="margin-top: 0cm;" type="disc"><li
id="jy:q17" class="MsoNormal" style="text-align: justify;">Prover      um ambiente consistente de programação orientada a objeto</li><li
id="jy:q18" class="MsoNormal" style="text-align: justify;">Executar código que minimiza o desenvolvimento de      software e conflitos de verão</li><li
id="jy:q19" class="MsoNormal" style="text-align: justify;">Eliminar os problemas de desempenho gerados por linguagens      de <em>script</em></li><li
id="jy:q20" class="MsoNormal" style="text-align: justify;">Aproveitar      o conhecimento do programador em diferentes tipos de aplicações, como      aplicações Windows ou <span
id="jy:q21" lang="EN-US">web</span></li><li
id="jy:q22" class="MsoNormal">Construir      toda a comunicação em padrões reconhecidos pela indústria para que o .NET <span
id="jy:q23" lang="EN-US">Framework</span> possa se      integrar com qualquer tipo de código</li></ul><p
style="text-align: justify;">Existem dois componentes principais na <em>plataforma .NET</em> : o <strong><span
id="jy:q27" lang="EN-US">Common</span> <span
id="jy:q29" lang="EN-US">Language</span> <span
id="jy:q31" lang="EN-US">Runtime</span></strong> (<em>CLR</em>) e o <strong>.NET <span
id="jy:q32" lang="EN-US">Framework</span> Class Library</strong>, que inclui o <em>ADO.NET</em>, <em>ASP.NET</em> e o <em>Windows <span
id="jy:q37" lang="EN-US">Forms</span></em>.</p><h3><span
id="jy:q41" lang="EN-US">Common</span> <span
id="jy:q43" lang="EN-US">Language</span> <span
id="jy:q45" lang="EN-US">Runtime</span> – CLR</h3><p>É o mecanismo responsável pela execução das aplicações <strong>.NET <span
id="jy:q49" lang="EN-US">Framework</span></strong>. O <strong>CLR </strong>é o responsável pela compilação do código-fonte das linguagens da <em>plataforma .NET</em>.</p><p
style="text-align: justify;">Veja os benefícios que o CLR nos proporciona:</p><ul
id="jy:q55" style="margin-top: 0cm;" type="disc"><li
id="jy:q56" class="MsoNormal" style="text-align: justify;">Gerenciamento      automático de memória(Garbage Collector)</li><li
id="jy:q57" class="MsoNormal" style="text-align: justify;">Verificação      de segurança de tipos</li><li
id="jy:q58" class="MsoNormal" style="text-align: justify;">Gerenciamento      de exceções</li><li
id="jy:q59" class="MsoNormal" style="text-align: justify;">Segurança      aprimorada</li><li
id="jy:q60" class="MsoNormal" style="text-align: justify;">Acesso      a metadados</li></ul><p><em><strong>OBS:</strong> </em>Não se preocupe muito com os conceitos agora, você vai entendê-los ao longo dos artigos. <img
src='http://www.guanabara.info/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p><h3><span
id="jy:q67" lang="EN-US">.NET Framework Class Library<br
/> </span></h3><p
style="text-align: justify;">É uma biblioteca de classes, interfaces e tipos. Ele permite acesso às funcionalidades do sistema e é a base da qual são construídas aplicações, componentes e controles. Imagine o Framework como sendo um grande facilitador do seu processo de programação, já que ele vem com a maioria dos códigos que você mais usa! Todos PRONTOS!</p><h2>Linguagem Intermediária – MSIL</h2><p
style="text-align: justify;">Quando o código é compilado pelo <strong>CLR</strong>, é gerado um <strong>Microsoft Intermediate Language</strong> (<em>MSIL</em>), ou simplesmente <strong>IL</strong>. Ele é independente da CPU e pode ser convertido para código nativo (<em>linguagem de máquina</em>).</p><p
style="text-align: justify;">O código contido em um <strong>IL </strong>não pode ser executado diretamente; antes de executá-lo é necessário convertê-lo em instruções de máquina para que possam ser interpretadas pela CPU utilizando o (<strong>JIT</strong>), que também foi abordado no podcast.</p><p
id="jy:q101" class="MsoNormal">Como o <strong>IL</strong> é independente de plataforma, só precisamos de um compilador para convertê-lo para código nativo.<span
id="jy:q94"> </span>Sendo assim, podemos desenvolver uma aplicação e convertê-la para várias plataformas. Basta somente que haja o <strong>JIT</strong> para a plataforma desejada.</p><h2>C#: A Linguagem</h2><p
id="jy:q118" class="MsoNormal"><strong>C# </strong>(<em>lê-se c-sharp</em>) é uma linguagem de programação simples, mas poderosa, ideal para desenvolver aplicações web com <em>ASP.NET</em>. Ele é uma variação do <strong>C</strong> e do <strong>C++</strong>. O <strong>C#</strong> possui um mecanismo chamado <em><strong>Garbage Collector</strong></em> (<em>Coletor de Lixo</em>) que gerencia de forma automática a memória utilizada pelas aplicações.<span
id="jy:q113"> </span>É uma linguagem totalmente orientada a objetos.</p><p
id="jy:q120" class="MsoNormal">Antes de começar a parte prática do desenvolvimento em <strong>C#</strong>, precisamos instalar alguns componentes necessário, são eles:</p><ul><li><strong><a
href="http://www.microsoft.com/express/download/" target="_blank">Visual C# Express</a></strong></li><li><a
href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en" target="_blank"><strong><span
id="jy:q127" lang="EN-US">.NET Framework 3.5<span
id="jy:q128"> </span></span></strong></a></li></ul><p
id="jy:q126" class="MsoNormal" style="text-align: justify;"><span
id="jy:q127" lang="EN-US">Clique em cada um dos links acima e baixe o C# Express e o .NET Framework. A instalação dos pacotes é simples e prática, bastando usar o método <em>Avançar &gt; Avançar &gt; Avançar &gt;&#8230; &gt; Concluir</em>. Talvez seja necessário dar um boot ou dois no seu computador. Uma vez instalados os pacotes, vamos continuar&#8230;<br
id="s3f_1" /></span></p><p
id="jy:q156" class="MsoNormal" style="text-align: justify;">Agora sim vamos ao que realmente interessa, escrever nosa <strong>primeira aplicação C#</strong> e entender um pouco sobre essa linguagem na prática.</p><p
id="jy:q159" class="MsoNormal" style="text-align: justify;">Abra o <strong>Visual C#</strong> e crie um novo arquivo – <em>Arquivo &gt; Novo Arquivo</em>. Ou simplesmente <em>Ctrl+N</em>.</p><p
style="text-align: justify;">Vamos escrever o programa <strong>Olá Mundo</strong>. Não se esqueça da maldição que explicamos no episódio 19 do podcast, onde esse deve ser o primeiro exercício em qualquer linguagem, ou você não aprenderá a programar nela. Salve este exercício em alguma pasta que seja fácil de chegar, exemplo:</p><p
style="text-align: center;"><strong>C:/Guanabara.info/Aula_1/</strong></p><p
class="MsoNormal"><em><strong>OBS: </strong></em>Salve com o nome <strong>OlaMundo.cs</strong>. (<em>onde .cs é a extensão de um arquivo C#</em>)</p><p
class="MsoNormal">A forma de escrever esse exercício é assim:</p><p
class="MsoNormal" style="text-align: center;"><img
class="alignnone size-medium wp-image-2759 aligncenter" title="C#: Tela1" src="http://www.guanabara.info/wp-content/uploads/2008/05/csharp1.jpg" alt="" /></p><p
id="jy:q182" class="MsoNormal" style="text-align: justify;">Agora algumas observações e explicações do código acima:</p><h3>Método Main</h3><p
style="text-align: justify;">Um programa em <strong>C# </strong>deve conter um método <em>Main</em>, que indica o início da aplicação. Nele você pode cria objetos e executar outros métodos. O método <em>Main </em>pode não retornar valores:</p><pre>static void Main(){
     ...</pre><pre>}</pre><p
id="jy:q203" class="MsoNormal">ou retornar um valor inteiro (int):</p><pre>static int Main() {
     ...</pre><pre>     Return 0;</pre><pre>}</pre><p
id="jy:q216" class="MsoNormal" style="text-align: justify;">Com os dois tipos (<em>void </em>ou <em>int</em>), o método <em>Main </em>pode ter parâmetros:</p><pre><span id="jy:q220" lang="EN-US">static void Main(string[] args) {</span>
     ...</pre><pre><span id="jy:q229" lang="EN-US">}</span></pre><p
id="jy:q245" class="MsoNormal"><span
id="jy:q246" lang="EN-US"> ou</span></p><pre><span id="jy:q251" lang="EN-US">static int Main(string[] args) {</span></pre><pre><span id="jy:q251" lang="EN-US">      ...</span></pre><pre><span id="jy:q255" lang="EN-US">     Return 0;</span></pre><p><span
id="jy:q259" lang="EN-US">}</span></p><h3>Sintaxe C#</h3><p
style="text-align: justify;">Todas as instruções devem estar entre chaves e sempre ser finalizadas com um ponto-e-vírgula, veja a seguir como:</p><pre><span id="jy:q279" lang="EN-US">{</span></pre><pre>     // Código aqui;</pre><pre>}</pre><h3>Entrada e Saída</h3><p
id="jy:q291" class="MsoNormal" style="text-align: justify;">A entrada de um programa <strong>C# </strong>é realizado pela <span
id="jy:q290"> </span>biblioteca de classes do <strong>.NET Framework</strong>. A instrução <em>System.Console.WriteLine(“Olá Mundo!”);</em> utiliza o método <em>WriteLine </em>da classe <em>Console</em>.</p><p
id="jy:q295" class="MsoNormal" style="text-align: justify;">Se alguns termos são desconhecidos para você, como por exemplo <em>classe</em>, <em>método</em>, <em>namespace</em> e <em>diretiva</em> não se preocupe, nas próximas aulas vamos explicando aos pouco cada um deles.</p><h3>Compilação e execução do Programa</h3><p
id="jy:q300" class="MsoNormal" style="text-align: justify;">Depois de ter instalado todos os componentes do .NET Franework necessário, como foi pedido antes da parte prática, vamos aprender a compilar e executar nosso programa OlaMundo seguindo os seguintes passos:</p><ol><li
style="text-align: justify;">Certifique-se que o arquivo <strong>OlaMundo.cs</strong> está salvo dentro do diretório <strong>C:/Guanabara.info/Aula_1/</strong>.</li><li
style="text-align: justify;">Em Seguida utilize o <strong>Visual Studio Command Prompt</strong>: Vá ao menu <em>Iniciar &gt; Programas &gt; Microsoft .NET Framework SDK &gt; SDK Command Prompt</em>.</li><li
style="text-align: justify;">Mude o diretório atual para <strong>C:/Guanabara.info/Aula_1</strong>.</li><li
style="text-align: justify;">Digite <strong>csc OlaMundo.cs</strong></li><li
style="text-align: justify;">Neste Momento você esta convertendo o código <strong>C# </strong>em<span
id="jy:q318"> </span><strong>IL</strong> e gerando um arquivo <strong>Potable Executable</strong> (<em>PE</em>) do tipo <strong>.exe</strong>.</li><li
style="text-align: justify;">Execute o programa digitando <strong>OlaMundo</strong> e pressione ENTER. Automaticamente o resultado será impresso na tela.</li></ol><p
id="jy:q329" class="MsoNormal" style="text-align: justify;">Bem galera, por hoje é só, esperamos ter conseguido passar uma informação legal para vocês, não evoluímos muito na linguagem hoje, foi só um aquecimento, nas próximas aulas daremos uma avançada maior.</p><p
id="jy:q333" class="MsoNormal" style="text-align: justify;">Qualquer dúvida, pergunta ou sugestão, basta deixar um comentário ou mande um e-mail que responderemos o mais rápido possível, caso não tenha dúvida e nem pergunta, deixe o seu comentário dizendo o que achou da nossa primeira parte do curso de <strong>C#</strong>.</p><p
class="MsoNormal" style="text-align: justify;">Agradeço a atenção de todos que chegaram ao fim deste artigo, e espero vocês na próxima. <img
src='http://www.guanabara.info/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /></p> ]]></content:encoded> <wfw:commentRss>http://www.guanabara.info/2008/05/c-ola-mundo/feed/</wfw:commentRss> <slash:comments>30</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: www.guanabara.info @ 2012-02-12 15:29:16 -->
