Visual studio feeds

All Visual Studio blogs in one place


Enter your email address:

Delivered by FeedBurner

Increase your website traffic with



Anti-spam: How many eyes has a typical person?

Follow us on FB


null is not false, part three

AddThis Social Bookmark Button
Returning now to the subject at hand: we would like to allow user-defined "overloads" of the & and | operators in C#, and if we are going to have & and | be overloadable, it seems desirable to have && and || be overloadable too. But now we have a big design problem. We typically overload operators by making a method: class C
  string s;
  public C(string s) { this.s = s; }
  public override string ToString() { return s; }
  public static C operator +(C x, C y) { return new C(x.s + "+" + y.s); }
C("123") + new C("456")); // "123+456" But method arguments are eagerly evaluated in C#. We can't very well say: public static C operator &&(C x, C y)  { ... whatever ... } because when you cay C c = GetFirstC() && GetSecondC(); that is going to be rewritten as something like: C c = C.op_ShortCircuitAnd(GetFirstC(), GetSecondC()); which obviously evaluates both operands regardless of whether the left hand is "true" or "false". Of course in modern-day C# we have a type which represents "perform this calculation that produces a result in the future, on demand"; that type is Func....(Read whole news on source site)

Home : Blog List : Fabulous Adventures In Coding : null is not false, part three