Permalink
Browse files

make Dog immutable

  • Loading branch information...
camilin87 committed Feb 1, 2016
1 parent 98c9adc commit dffbd97927070b05c623192a788a33b97e7101c7
Showing with 11 additions and 5 deletions.
  1. +11 −5 Program.cs
@@ -5,8 +5,14 @@ namespace consoleapplication1
{
public class Dog
{
public int Weight { get; set; }
public string Name { get; set; }
public int Weight { get; }
public string Name { get; }

public Dog(string name, int weight)
{
this.Name = name;
this.Weight = weight;
}

public override bool Equals(object obj)
{
@@ -28,10 +34,10 @@ public class Program
public static void Main(string[] args)
{
var dogShelter = new Dictionary<Dog, int>{
{new Dog { Name = "Fido", Weight = 12 }, 100},
{new Dog { Name = "Pete", Weight = 5 }, 10}
{new Dog("Fido", 12), 100},
{new Dog("Pete", 5), 10}
};
var fido = new Dog { Name = "Fido", Weight = 12 };
var fido = new Dog("Fido", 12);

Console.WriteLine(dogShelter.ContainsKey(fido));
}

0 comments on commit dffbd97

Please sign in to comment.