DotNetKick.com is an open-source project. Please report any bugs and let us know your great suggestions. Currently running svn revision 620 (rss)

Kick Spy!, Kick Zeitgeist and Kick Widgets

2
kicks
submitted by kasuken 2 months, 21 days ago

blog.emanuelebartolesi.com — The equivalent operator in C# for IIF.

Add a comment 3 comments | category: | Views: 42 | Get KickIt image code
tags: , | tag it

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:

Comments:
Actually the C# ternary operator isn't equivalent to IIF in VB, because the IIF function always evaluates both the true and false actions, whereas the ?: operator is a lazily evaluated left-associative operator which only associates the appropriate action. e.g. IIf(a IsNot Nothing, a.ToLower(), String.Empty) will throw a NullReferenceException in VB if a is null because it will try to evaluate a.ToLower() anyway, whereas a != null ? a.ToLower() : string.Empty will not throw in C#. The C# ternary operator didn't have an equivalent in VB until VB9, where you can now write the rather confusing If(a IsNot Nothing, a.ToLower(), String.Empty).
posted by gregbeech 2 months, 21 days ago
Logically it is the same, but it looks like it isn't technically the same (good tip gregbeech)
posted by zowens zowens 2 months, 21 days ago
IIf is evil. Other then the reason mentioned by gregbeech, the other thing is that it returns an Object so in most cases you would need to cast it before assigning the evaluated expression
posted by drugarce drugarce 2 months, 20 days ago



information Login or create an account to comment on this story
 

Sponsored Link: www.carlist.ie

Search:

Ads via The Lounge