This blog has moved!

Check out www.CodeBetter.com/blogs/grant.killian

<July 2008>
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789


Navigation

Professional Props...

Extracurricular Props...

Subscriptions

Article Categories



Tuesday, March 02, 2004 - Posts

Some VB Static

After a bit of time away, I'm teaching part-time again.  We were covering static members in VB and it ocurred to me (and the class) that static methods in VB exhibit different behaviour than in C#.  I do a lot of my programming with C#, and I was explaining how Shared (the VB equivalent to the C# static keyword) methods are available through instances of the class instead of just the type itself.  So, if I make a DeckOfCards object with a Shared (static) method named Sort(), the following is valid VB.Net:

dim objInstance as DeckOfCards = new DeckOfCards()
objInstance.Sort( args )

In C#, the only way to call the static Sort method is through the type:

DeckOfCards.Sort( args );

Four things strike me:

  1. This is a fairly trivial thing . . .
  2. . . . Except that, to be technically correct, it means you have to caveat your explanation of Static methods based on each language.
  3. This is possibly (although I'm not sure) why VB.Net uses the keyword Shared in place of “static“.  Shared is not completely identical to the C# static.
  4. I like the c# way better; it's cleaner.  For example, the next question a student will ask is “can I reference the current instance though the Shared member?“  The rationale for static/shared methods comes into question . . .

I can't think of a “good” reason for VB.Net exhibiting this behaviour, but I'm not on the VB.Net language team so who knows; it's not the first strange difference I've seen (see my post here for example) and it won't be my last.  Anyway, I thought I should document it here for posterity.

Happy .Netting!

posted Tuesday, March 02, 2004 1:20 PM by grant.killian

Mahalo in Advance for the Attribute Summary

Just got back from a little holiday on a Pacific island where mahalo means Thank you . . . this was one of those vacations that helps me rationalize all the long hours during the rest of the year!

Regarding the title of this post, a buddy asked me if I knew of a definitive resource on Attributes in the .Net Framework.  You know: a directory of each available attribute, the usage, and rationale.  I know the O'Reilly Programming VB.Net (by Grundgeiger) has an appendix listing Attributes and discusses the topic in some detail.

Besides the O'Reilly book, I didn't know of anything off-hand and from googling etc, I couldn't find anything so I told him I wasn't aware of anything complete.  This seemed like something useful so I began listing the ones I knew of and used, thinking I could blog about a few attributes each day for a while . . . but then I decided to ask you all -- the blog public -- first . . .

Do you know of an authoritative guide to the .Net Attributes available?

Mahalo in advance!

 

posted Tuesday, March 02, 2004 9:08 AM by grant.killian




Powered by Dot Net Junkies, by Telligent Systems