26.08.2014 Views

C# e Orientação a Objetos

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

137 STRING<br />

Código <strong>C#</strong> 15.7: Split()<br />

Replace()<br />

O método Replace() cria uma cópia de uma string substituindo “pedaços” internos por outro<br />

conteúdo.<br />

1 string texto = " Curso de CSharp da K19 , Curso de ASP . NET MVC da K19 ";<br />

2<br />

3 string textoAlterado = texto . Replace (" Curso "," Treinamento ");<br />

4<br />

5 // imprime Treinamento de CSharp da K19 , Treinamento de ASP . NET MVC da K19<br />

6 System . Console . WriteLine ( textoAlterado );<br />

Código <strong>C#</strong> 15.8: Replace()<br />

Exercícios de Fixação<br />

1 Crie um projeto no Microsoft Visual <strong>C#</strong> Express chamado String.<br />

2 Teste a imutabilidade das strings.<br />

1 public class TestaImutabilidade<br />

2 {<br />

3 public static void Main ()<br />

4 {<br />

5 string nome = " Rafael Cosentino ";<br />

6<br />

7 string nomeAlterado = nome . ToUpper ();<br />

8<br />

9 // imprime Rafael Cosentino<br />

10 System . Console . WriteLine ( nome );<br />

11<br />

12 // imprime RAFAEL COSENTINO<br />

13 System . Console . WriteLine ( nomeAlterado );<br />

14 }<br />

15 }<br />

Código <strong>C#</strong> 15.9: TestaImutabilidade.cs<br />

www.facebook.com/k19treinamentos 137

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!