Tuesday, April 01, 2008

C# quiz: 3/?

Consider the following class:

    internal class Test {

public int Code { get; set; }

public static bool operator ==(Test lhs, Test rhs) {
if (object.ReferenceEquals(lhs, rhs)) return true;
if (lhs == null || rhs == null) {
return false;
} else {
return lhs.Code == rhs.Code;
}
}

public static bool operator != (Test lhs, Test rhs) {
return !(lhs == rhs);
}
}

What is the outcome of the following test code, and why?

            Test test1 = new Test { Code = 42 };
Test test2 = new Test { Code = 42 };
if (test1 != test2) {
Console.WriteLine("different");
} else {
Console.WriteLine("equals");
}

Monday, March 31, 2008

C# quiz: 2/?

Continuing on the series of C# and/or .NET Framework short questions:

        private void Foo(List<int> bar) {
bar = new List<int>();
// ...
}

With the method above and the code below:

        List<int> bar = null;
Foo(bar);
if (bar != null) {
Console.WriteLine("populated");
} else {
Console.WriteLine("still null");
}
If or else ?

EDIT: fixed typo in code sample.

C# quiz: 1/?

I'm starting a series with small questions C# and/or .NET Framework related questions:

First out, NaN values:

            double foo = double.NaN;
// ...
if (foo == double.NaN) {
Console.WriteLine("NaN");
} else {
Console.WriteLine("a number");
}

If or else ?

Wednesday, March 19, 2008

Safari - first impressions

I thought that I might give it a shot after all so I installed it. First impressions:

- it's a memory hog! 4 sites in 4 tabs consumes a whopping 210MB, while Firefox 3 beta 4 for the same sites consumes "only" 74MB

- the UI is ugly

- scroll wheel doesn't work properly in bookmarks

- close tab X button on the left !?!

- As I don't have mouse gestures, I often right-click and choose back. If I happen to have the cursor over a word, (quite likely), safari chooses to select the word and only select search with google or copy. WTF?

...my default browser isn't changing.

Tuesday, March 18, 2008

Safari for Windows - Apple spamming users

I have an ipod, and therefore I have ITunes installed. Today Apple Software Update popped up and greeted me with the following totally unrelated thing: Safari 3.1 (22.65Mb)

Safari for Windows is the fastest and easiest-to-use web browser for the PC.  It displays web pages faster than any other browser and is filled with innovative features -- all delivered in an efficient and elegant user interface.

For more information on Safari 3.1, please visit http://docs.info.apple.com/article.html?artnum=307467

Hmm, that sounds too good to be true.

...and why does it notify me about it in the first place?

Friday, March 14, 2008

Gotcha: Hidden [Flags] attribute on bitfield enumerations

 

Just got reminded of a still unfixed bug.

Consider an enumeration of the following kind:

    /// <summary>
/// Modes enumeration
/// </summary>
[Flags]
public enum Modes {
/// <summary>
/// Yes
/// </summary>
Foo = 1,
/// <summary>
/// No
/// </summary>
Bar = 2,
/// <summary>
/// Maybe
/// </summary>
Both = Foo|Bar
}

For the user of this enumeration, it is essential to know that it in fact is a bitfield (as specified by the FlagsAttribute).


However, both Intellisense and object browser fails to give any hint about this fact!?! (Yes, this occurs in both VS 2005 and VS 2008)


So for now, remember to document (within in the summary, so it is visible) this fact for your fellow developers.


Tuesday, January 15, 2008

New phone

I received my new phone today, this time I thought I'd try something different for various reasons, so I got a HTC Touch Dual. I haven't really used it enough yet to post any reviews, but first impression is quite nice. Unfortunately it still takes two weeks until I they switch over to the new SIM card (due to carrier change), so until then I cannot really use it fully. But yes, I will keep my old number...

On a related note, things don't seem as bright with the handsfree that I got, it was cheap yes, but first it had the wrong kind of mains plug on the charger, and secondly after I found an appropriate adapter, the thing won't charge !?!