Last active
August 29, 2015 14:06
-
-
Save AlbertoMonteiro/c537877de25aee0108d3 to your computer and use it in GitHub Desktop.
Comparativo C# 5 e C# 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApplication2 | |
{ | |
public class ExceptionCSharp5 : Exception | |
{ | |
public ExceptionCSharp5() | |
: base("Mensagem") | |
{ } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApplication2 | |
{ | |
public class ExceptionCSharp6() : Exception("Mensagem") { } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ConsoleApplication2 | |
{ | |
public class PessoaCSharp5 | |
{ | |
public PessoaCSharp5(string primeiroNome, string segundoNome, int idade) | |
{ | |
PrimeiroNome = primeiroNome; | |
SegundoNome = segundoNome; | |
Idade = idade; | |
} | |
public int Idade { get; set; } | |
public string PrimeiroNome { get; set; } | |
public string SegundoNome { get; set; } | |
public string NomeCompleto | |
{ | |
get | |
{ | |
return string.Format("{0} {1}", PrimeiroNome, SegundoNome); | |
} | |
} | |
public override string ToString() | |
{ | |
return string.Format("{0} tem {1} anos", NomeCompleto, Idade); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ConsoleApplication2 | |
{ | |
public class PessoaCSharp6(string primeiroNome, string segundoNome, int idade) | |
{ | |
public int Idade { get; set; } = idade; | |
public string PrimeiroNome { get; set; } = primeiroNome; | |
public string SegundoNome { get; set; } = segundoNome; | |
public string NomeCompleto => string.Format("{0} {1}", PrimeiroNome, SegundoNome); | |
public override string ToString() => string.Format("{0} tem {1} anos", NomeCompleto, Idade); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
namespace ConsoleApplication2 | |
{ | |
public class TrataExcessaoCSharp5 | |
{ | |
public void BaixaAlgo() | |
{ | |
var request = (HttpWebRequest)HttpWebRequest.Create("http://www2.enderecoquenaoexiste.com"); | |
try | |
{ | |
var response = request.GetResponse(); | |
} | |
catch (WebException ex) | |
{ | |
if (ex.Status == WebExceptionStatus.Timeout) | |
Console.WriteLine("Timeout"); | |
else if (ex.Status == WebExceptionStatus.ConnectFailure) | |
Console.WriteLine("ConnectFailure"); | |
else if (ex.Status == WebExceptionStatus.NameResolutionFailure) | |
Console.WriteLine("NameResolutionFailure"); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
namespace ConsoleApplication2 | |
{ | |
class TrataExcessaoCSharp6 | |
{ | |
public void BaixaAlgo() | |
{ | |
var request = (HttpWebRequest)HttpWebRequest.Create("http://www2.enderecoquenaoexiste.com"); | |
try | |
{ | |
var response = request.GetResponse(); | |
} | |
catch (WebException ex) if (ex.Status == WebExceptionStatus.Timeout) | |
{ | |
Console.WriteLine("Timeout"); | |
} | |
catch(WebException ex) if (ex.Status == WebExceptionStatus.ConnectFailure) | |
{ | |
Console.WriteLine("ConnectFailure"); | |
} | |
catch (WebException ex) if (ex.Status == WebExceptionStatus.NameResolutionFailure) | |
{ | |
Console.WriteLine("NameResolutionFailure"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment