Skip navigation.

Book Review: Implementation PatternsAll recent postsWhere Is C# Heading?

Creepy Implicitness

Generally, I’m not against implicit operators, but this LINQ/XML syntax gives me creeps:

new XAttribute (XNamespace.Xmlns + "foo", "bar")

Took me a while to understand that XNamespace has an implicit operator which allows this string “concatenation.”

Comments

Comment permalink 1 Patrik |
I think the rule of thumb for using implicit operators is that they're fine as long as you don't lose any information when doing the cast, in other words as long as the object you end up with can be used to create a new object of the original type and they're considered equal.

So I'd say that this is a mighty fine example of the implicit operator when used at it's best.

Emails and Notifications

Would you like to be notified when somebody responds to this post?  Would you like to have these comments emailed to you?

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):