locked
What's the Exclamation Mark Mean? - MsgBox(schematable.Rows(i)!TABLE_NAME.ToString) RRS feed

  • Question

  • I'm sorry.  I do know how to use Google but I am just unable to understand the exclamation mark in the line of code in the subject.  It's seems that sometimes it is used to specify type but sometimes represents a default property, but what's a default property?  I don't see any property of DataRowCollection identified as the default property.

    Can someone please show me the longhand version of the statement in the subject?

    (If anyone is wondering the code does work in VBE 2010!)

    Thanks,  Bob


    • Edited by eBob.com Thursday, June 28, 2012 2:47 PM
    Thursday, June 28, 2012 2:44 PM

Answers

  • Hi eBob,

    I wasn't even aware that ancient syntax is still valid.  lol

    Rows(i) returns a DataRow. The default property of a DataRow is the Item property. So it's equal to

    schematable.Rows(i).Item("TABLE_NAME")

    or in short

    schematable.Rows(i)("TABLE_NAME")



    Armin

    Thursday, June 28, 2012 3:46 PM

All replies

  • Hi eBob,

    I wasn't even aware that ancient syntax is still valid.  lol

    Rows(i) returns a DataRow. The default property of a DataRow is the Item property. So it's equal to

    schematable.Rows(i).Item("TABLE_NAME")

    or in short

    schematable.Rows(i)("TABLE_NAME")



    Armin

    Thursday, June 28, 2012 3:46 PM
  • Hi Armin,

    Thanks very much.  The part I still do not get is how anyone is supposed to know that the Item property is the default property.  I can't find any documentation which says so.  But the ! syntax is so rare that I don't think I am going to worry about it.

    Thanks again,  Bob

    Friday, June 29, 2012 2:38 AM
  • You're right! Not even the documentation mentions that. Only if you select the Item property in the object browser, you see

          Default Public ReadOnly Property Item(ByVal index As Integer) As System.Data.DataRow



    Armin

    Friday, June 29, 2012 11:47 AM
  • Hi Armin,

    Thanks very much.  The part I still do not get is how anyone is supposed to know that the Item property is the default property.  I can't find any documentation which says so.  But the ! syntax is so rare that I don't think I am going to worry about it.

    Thanks again,  Bob

    Precisely what you state is why we should be trying to get away from 'default' properties - it adds to confusion and obfuscates code. That is, one should always explicitly call the property even though it is the default property.

    Stephen J Whiteley

    Friday, June 29, 2012 6:28 PM
    Moderator