Skip to content

Instantly share code, notes, and snippets.

@callionica
Created December 12, 2015 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callionica/aa717a61d5c7b76d923e to your computer and use it in GitHub Desktop.
Save callionica/aa717a61d5c7b76d923e to your computer and use it in GitHub Desktop.
// 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