The Artima Developer Community
Sponsored Link

.NET Buzz Forum
VB.NET stupidity

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frans Bouma

Posts: 265
Nickname: fbouma
Registered: Aug, 2003

Frans Bouma is a senior software engineer for Solutions Design
VB.NET stupidity Posted: Feb 22, 2004 7:51 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Frans Bouma.
Original Post: VB.NET stupidity
Feed Title: Frans Bouma's blog
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/fbouma/Rss.aspx
Feed Description: Generator.CreateCoolTool();
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Frans Bouma
Latest Posts From Frans Bouma's blog

Advertisement

Consider the following enum definition (which is defined in a C# assembly)

public enum EntityState:int
{
   New,
   Fetched,
   OutOfSync,
   Deleted
}

OK, now, we have an object which has a property called 'State' and this property is of type EntityState. All great, let's set that property State to EntityState.New in VB.NET:

myObject.State = EntityState.New

Does this statement compile or not? I give you a hint: when I press '.' after EntityState, the intellisense of VS.NET does understand it's an enum and gives the 4 values possible.

No! It does not compile! I even have defined Option Strict, but the VB.NET compiler thinks I'm calling Public Sub New() on EntityState even though I have omitted '()' and the compiler comes up with this brilliant knowledge: "Type '...EntityState' has no constructors'. Gee..., really? Perhaps that was the reason I didn't specify '()' so you might already have known it wasn't a method call, it was an enum value specification, dear compiler.

I have to specify:

myObject.State = EntityState.[New]

What a magnificant solution... Instead of fixing the syntax once and for all: always require '()' for a method call, they opt for a horrible workaround: "add [] around the name that confuses the compiler". Apparently even though the compiler knows it's an enum type and the value is a value of that enum type.

Read: VB.NET stupidity

Topic: A Quick Look At the Win2K Stolen Source Previous Topic   Next Topic Topic: Here's a great list of tips on Optimzing Performance with Virtual PC (VPC)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use