Skip to content

Instantly share code, notes, and snippets.

View ThomasArdal's full-sized avatar
🎢

Thomas Ardal ThomasArdal

🎢
View GitHub Profile
@ThomasArdal
ThomasArdal / SomeClass.cs
Last active August 29, 2015 14:06
Try catch with exception filters
try
{
DoSomeHttpRequest();
}
catch (System.Web.HttpException e) if (e.GetHttpCode() == 400)
{
WriteLine("Not Found");
}
catch (System.Web.HttpException e) if (e.GetHttpCode() == 500)
{
@ThomasArdal
ThomasArdal / SomeClass.cs
Last active August 29, 2015 14:06
Standard try catch
try
{
DoSomeHttpRequest();
}
catch (System.Web.HttpException e)
{
switch (e.GetHttpCode())
{
case 400:
WriteLine("Bad Request");
@ThomasArdal
ThomasArdal / Program.cs
Created September 25, 2014 08:17
Static usings
using System.Console;
...
if (bool.TryParse("true", out var result))
{
WriteLine("This is a bool with value. " + result);
}
else
{
@ThomasArdal
ThomasArdal / Program.cs
Last active August 29, 2015 14:06
Decompiled TryParse boolean with declaration expression
bool flag;
if (bool.TryParse("true", out flag))
{
Console.WriteLine("This is a bool with value. " + flag);
}
else
{
Console.WriteLine("Not a bool, yo! " + flag);
}
@ThomasArdal
ThomasArdal / Program.cs
Created September 25, 2014 08:07
TryParse boolean with declaration expression
if (bool.TryParse("true", out var result))
{
Console.WriteLine("This is a bool with value. " + result);
}
else
{
Console.WriteLine("Not a bool, yo! " + result);
}
@ThomasArdal
ThomasArdal / Program.cs
Last active August 29, 2015 14:06
TryParse boolean
bool result;
if (bool.TryParse("true", out result))
{
Console.WriteLine("This is a bool with value. " + result);
}
else
{
Console.WriteLine("Not a bool, yo! " + result);
}
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Decompiled Movie class with multiple constructors
public class Movie
{
private readonly string <Title>k__BackingField
private readonly List<string> <Genres>k__BackingField;
private readonly int <Runtime>k__BackingField
public string Title
{
get { return this.<Title>k__BackingField; }
}
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Movie class with multiple constructors
public class Movie(string title, List<string> genres)
{
public string Title { get; } = title;
public List<string> Genres { get; } = genres;
public int Runtime { get; private set; }
public Movie(string title, List<string> genres, int runtime) : this(title, genres)
{
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Decompiled Movie class with default constructor
public class Movie
{
private readonly string <Title>k__BackingField
private readonly List<string> <Genres>k__BackingField;
public string Title
{
get { return this.<Title>k__BackingField; }
}
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Movie class with default constructor
public class Movie(string title, List<string> genres)
{
public string Title { get; } = title;
public List<string> Genres { get; } = genres;
}