December 2008 Entries

Ternary If Statement in C#

Sometimes you just need a ternary statement, i.e. you don't want to return a value from the condition ? true : false construct. Here is an extension method to help you out (the usage example isn't the best). class Program { static void Main(string[] args) { List<string> test = new List<string>(); ArrayList source = new ArrayList(); source.Add(1); source.Add("hello"); source.Each<object>(x => (x is String).IfElse ( () => test.Add((string)x), () => test.Add(x.ToString())...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Ruby-like each statement in C#

Funny this isn't in the provided Enumerable extension methods. In any case, here it is: internal static void Each<T>(this IEnumerable<T> @this, Action<T> action) { foreach(T t in @this) action(t); } internal static void Each<T>(this IEnumerable @this, Action<T> action) { foreach (object t in @this) if (t is T) { action((T)t); } } An example: objects.Each(x => DoSomethingFunky(x, "some parameter"));...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Using Is.Gd/Bitly/TinyUrl/Facebook Post in Chrome

Put your favorite bookmarklet at your fingertips.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910