Skip to content

Instantly share code, notes, and snippets.

View ThomasArdal's full-sized avatar
🎢

Thomas Ardal ThomasArdal

🎢
View GitHub Profile
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Class containing auto-properties with default values
public class Movie
{
public string Title { get; private set; }
public List<string> Genres { get; private set; }
public Movie()
{
Title = "The Big Lebowski";
Genres = new List<string> { "Comedy", "Crime" };
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Class containing auto-properties with default values through initializers
public class Movie
{
public string Title { get; } = "The Big Lebowski";
public List<string> Genres { get; } = new List<string> { "Comedy", "Crime" };
}
@ThomasArdal
ThomasArdal / Movie.cs
Last active August 29, 2015 14:06
Class containing auto-properties with default values through initializers (decompiled)
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
Created September 24, 2014 12:55
Movie class with constructor
public class Movie
{
public string Title { get; private set; }
public List<string> Genres { get; private set; }
public Movie(string title, List<string> genres)
{
Title = title;
Genres = genres;
@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;
}
@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 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 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 / 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 / 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);
}