Created
December 12, 2015 00:02
-
-
Save callionica/aa717a61d5c7b76d923e to your computer and use it in GitHub Desktop.
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
// C# equivalent of buckets.swift | |
using System; | |
using System.Collections.Generic; | |
interface IFeed { | |
String url { get; } | |
} | |
class LocalFeed : IFeed { | |
public String url { get; set; } | |
public LocalFeed() { this.url = "file://local"; } | |
} | |
class RemoteFeed : IFeed { | |
public String url { get; set; } | |
public RemoteFeed() { this.url = "http://remote"; } | |
} | |
class FeedEquality : IEqualityComparer<IFeed> { | |
public Boolean Equals(IFeed lhs, IFeed rhs) { | |
return lhs.url == rhs.url; | |
} | |
public Int32 GetHashCode(IFeed feed) { | |
return feed.url.GetHashCode(); | |
} | |
} | |
class Bucket { | |
public ISet<IFeed> feeds = new HashSet<IFeed>(new FeedEquality()); | |
public void Add(IFeed feed) { | |
feeds.Add(feed); | |
} | |
} | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var bucket = new Bucket(); | |
bucket.Add(new LocalFeed()); | |
bucket.Add(new RemoteFeed()); | |
foreach (var feed in bucket.feeds) { | |
Console.WriteLine(feed.url); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment