Updates from November, 2010 Toggle Comment Threads | Keyboard Shortcuts

  • Richard 8:53 am on November 9, 2010 Permalink |  

    The silverlight gallery effect 

    Having just launched a Micro ISV (more about this in another post) I have been attempting to do some marketing. I started by searching twitter for people talking about the kind of technology my ISV does, and sending them a tweet introducing them to my website. You can see the small ripples half way along the graph. Then I got accepted into the Microsoft Silverlight Community Gallery and you can instantly see the difference.

    Getting some publicity on a big site (even in a small way) seems to be delivering high traffic consistently.

     

    Advertisements
     
  • Richard 11:44 am on November 8, 2010 Permalink |  

    Enum.Parse 

    When you parse an enum in .NET, if you pass in a value which isn’t in the enum, you’ll still get an enum value out again.

    This piece of code will write out ‘3’.

     
    enum Example
    {
    	Value0 = 0,
    	Value1 = 1
    }
    
    public static void RunSnippet()
    {
    	Console.WriteLine( Enum.Parse(typeof(Example), "3") );
    }
    
    
    However, there is another method 'IsDefined' which will tell you if the value held by the enum is a valid value. So this method will parse your enum, and will return the default if the value isn't valid:
    
    private static T ParseEnum(string value)
    {
    	T t = (T)Enum.Parse(typeof(T), value);
    	if (Enum.IsDefined(typeof(T), t))
    	{
    		return t;
    	}
    	return default(T);
    }
     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel