Syntax question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I stumbled across an older post:

http://msdn.microsoft.com/newsgroup...&pt=&catlist=&dglist=&ptlist=&exp=&sloc=en-us

Which uses the ! in a way I haven't seen before and I'm having trouble
figuring out what it's doing there. The line is:

=CDate(Parameters!StartDate.Value).AddMonths(-1).ToString("MMMM")

The only thing I've found on ! is that it indicates:
"Appending the identifier type character ! to any identifier forces it to
Single." (From .NET 1.1 Framework docs) but that is for vb.net and not c#, so
I don't think it would apply.

Anyone have any insight on this?

-Ben
 
Ben R. said:
I stumbled across an older post:

http://msdn.microsoft.com/newsgroup...&pt=&catlist=&dglist=&ptlist=&exp=&sloc=en-us

Which uses the ! in a way I haven't seen before and I'm having trouble
figuring out what it's doing there. The line is:

=CDate(Parameters!StartDate.Value).AddMonths(-1).ToString("MMMM")

The only thing I've found on ! is that it indicates:
"Appending the identifier type character ! to any identifier forces it to
Single." (From .NET 1.1 Framework docs) but that is for vb.net and not c#,
so
I don't think it would apply.

'!' can be used with default properties to access a certain item.

\\\
Dim c As New Collection
c.Add("Bla", "Goo")

' Semantically equivalent lines.
MsgBox(c!Goo)
MsgBox(c("Goo"))
MsgBox(c.Item("Goo"))
///
 
Very interesting. Is there any documentation out there on this? Must the
accessor be a string? You're using "goo" with quotes and then with the !,
it's not with quotes so I'm assuming this is implied. Does this mean you
couldn't use, say, an integer accessor?
 
Ben,

Ben R. said:
Very interesting. Is there any documentation out there on this? Must the
accessor be a string? You're using "goo" with quotes and then with the !,
it's not with quotes so I'm assuming this is implied. Does this mean you
couldn't use, say, an integer accessor?

It will only work with classes which have a default property which accepts a
single string parameter:

Visual Basic Language Concepts -- Special Characters in Code
<URL:http://msdn2.microsoft.com/en-us/library/xxda45fy.aspx>
-> "Exclamation Point ('!') Operator"
 
You can find documentation here:
http://msdn2.microsoft.com/en-us/library/xxda45fy.aspx

According to this document, the class must have a default property that
accepts a String as an argument. So it won't work with integers.

I believe this is around from VB6, actually, and that is why it is in .NET.
It's a compatibility issue, instead of MS thinking this would be a nice
feature to have around.
 
Back
Top